SQL string as a data source

J

John

Hi

I would appreciate if someone could kindly give an example of how an sql
string can be turned into a data source. I would specifically need to assign
the data source to a binding source.

Thanks

Regards
 
M

Miha Markic

Are you saying thta you want to execute a select on database and use the
result as data source?
You'd need to use a database specific dataadapter to fill the table. Then
you can use that table as a data source. You can use database specific
datareader as well in some cases.
 
J

John

Hi Miha

Thanks. Basically I am stuck at how to turn a given sql into a data table
which I can use as data source.

Thanks

Regards

Miha Markic said:
Are you saying thta you want to execute a select on database and use the
result as data source?
You'd need to use a database specific dataadapter to fill the table. Then
you can use that table as a data source. You can use database specific
datareader as well in some cases.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

John said:
Hi

I would appreciate if someone could kindly give an example of how an sql
string can be turned into a data source. I would specifically need to
assign the data source to a binding source.

Thanks

Regards
 
M

Miha Markic

You can try something like this:
DataTable table = new DataTable();
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT bla bla",
connectionString))
{
adapter.Fill(table);
}

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

John said:
Hi Miha

Thanks. Basically I am stuck at how to turn a given sql into a data table
which I can use as data source.

Thanks

Regards

Miha Markic said:
Are you saying thta you want to execute a select on database and use the
result as data source?
You'd need to use a database specific dataadapter to fill the table. Then
you can use that table as a data source. You can use database specific
datareader as well in some cases.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

John said:
Hi

I would appreciate if someone could kindly give an example of how an sql
string can be turned into a data source. I would specifically need to
assign the data source to a binding source.

Thanks

Regards
 
J

Jonathan Wood

In order to serve as a data source, you also need to define the database
server and the connection string needed to connect to that server. Once you
have that, you can also provide the SQL statement.

You can't create a data source from only a SQL string.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
http://www.softcircuits.com/blog/

John said:
Hi Miha

Thanks. Basically I am stuck at how to turn a given sql into a data table
which I can use as data source.

Thanks

Regards

Miha Markic said:
Are you saying thta you want to execute a select on database and use the
result as data source?
You'd need to use a database specific dataadapter to fill the table. Then
you can use that table as a data source. You can use database specific
datareader as well in some cases.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

John said:
Hi

I would appreciate if someone could kindly give an example of how an sql
string can be turned into a data source. I would specifically need to
assign the data source to a binding source.

Thanks

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top