SQL string as a data source

  • Thread starter Thread starter John
  • Start date Start date
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
 
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.
 
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
 
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
 
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
 
Back
Top