Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Send Records Straight To DataTable

Reply
Thread Tools

Send Records Straight To DataTable

 
 
Beza
Guest
Posts: n/a
 
      06-27-2003
I know how to use the Fill method of a SqlDataAdapter (into a DataSet) but
it seems quite long winded, if I just want to get the results into a
DataTable object. Is there a better way of doing this?


 
Reply With Quote
 
 
 
 
William F. Robertson, Jr.
Guest
Posts: n/a
 
      06-27-2003
It isn't long winded at all.

DataTable dt = new DataTable();
SqlDataAdapter sa = new SqlDataAdapter();
sa.SelectCommand = new SqlCommand();
sa.SelectCommand.Connection = new SqlConnection( "connectionstring" );
sa.SelectCommand.CommandText = "Select * from *";

sa.SelectCommand.Connection.Open();
sa.Fill( dt );

You can combine some of these lines together with the constructor, but I was
just showing you the easy way to follow.

HTH,

bill


"Beza" <> wrote in message
news:...
> I know how to use the Fill method of a SqlDataAdapter (into a DataSet) but
> it seems quite long winded, if I just want to get the results into a
> DataTable object. Is there a better way of doing this?
>
>



 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      06-27-2003
Use a DataReader to get the data. Then create a new instance of a DataTable.
Then loop through the DataReader, adding a row to the DataTable with each
pass, and fill the columns of the row from the columns of the DataReader
row.

HTH,

Kevin Spencer
Microsoft FrontPage MVP
Internet Developer
http://www.takempis.com
Big things are made up of
lots of Little things.

"Beza" <> wrote in message
news:...
> I know how to use the Fill method of a SqlDataAdapter (into a DataSet) but
> it seems quite long winded, if I just want to get the results into a
> DataTable object. Is there a better way of doing this?
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort a datatable and create a new datatable Fredrik Rodin ASP .Net 3 09-28-2007 07:28 AM
How can I add a row from a typed datatable to another instance of that typed datatable? Ersin Gençtürk ASP .Net 1 10-06-2004 01:11 PM
Create a Datatable from a SQL datatable column shema? jg ASP .Net 1 08-17-2004 09:43 PM
Casting DataTable to class inherit from DataTable =?Utf-8?B?Qmx1ZWZsb3dlcg==?= ASP .Net 0 04-02-2004 05:41 AM
Adding DataTable Rows To another DataTable J. Babe ASP .Net 1 08-15-2003 05:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57