469,580 Members | 1,883 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,580 developers. It's quick & easy.

sqldatasource to fill a datatable

Can I use a sqlDataSource to fill a datatable in code? How?
Thanks,
T
Aug 16 '07 #1
2 5037
Hi Tina,
SqlDataSource is component used for databinding. If you need to fill
DataTable in your code use SqlDataAdapter instead.

DataTable table = new DataTable();
using (SqlConnection conn = new SqlConnection(myConnectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("some database query", conn);
adapter.Fill(table);
}

Best regards,
Ladislav

"Tina" wrote:
Can I use a sqlDataSource to fill a datatable in code? How?
Thanks,
T
Aug 17 '07 #2
I'm aware of what you are saying.
My question stands.
T

"Ladislav Mrnka" <La***********@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Hi Tina,
SqlDataSource is component used for databinding. If you need to fill
DataTable in your code use SqlDataAdapter instead.

DataTable table = new DataTable();
using (SqlConnection conn = new SqlConnection(myConnectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("some database query", conn);
adapter.Fill(table);
}

Best regards,
Ladislav

"Tina" wrote:
>Can I use a sqlDataSource to fill a datatable in code? How?
Thanks,
T

Aug 17 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sam_Chou | last post: by
8 posts views Thread by cider123 | last post: by
1 post views Thread by VB Programmer | last post: by
1 post views Thread by Per W. | last post: by
1 post views Thread by jobs | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.