Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataAdapter.Fill() method
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
DataAdapter.Fill() method
Environment versions
Environment:
C# 2.0
Database:
MS SQL Server
Miscellaneous
Thread ID:
01096461
Message ID:
01096461
Views:
56
Again something works differently than how I expected it to work.
I have a table with 3 fields (field1, field2 and field3). I created a typed dataset from that table, but I removed field3 so the dataset only has 2 fields (field1 and field2).
I run the following code:
DataSet1 ds = new DataSet1();
MessageBox.Show("Coulumns.Count: " + ds.Table2.Columns.Count.ToString(), "before");

SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("SELECT field1, field2, field3 FROM Table2", new SqlConnection("Data Source=localhost;Initial Catalog=Test;Integrated Security=SSPI;"));
adapter.Fill(ds, ds.Table2.TableName);

MessageBox.Show("Coulumns.Count: " + ds.Table2.Columns.Count.ToString(), "after");
The first msgbox (with title before) displays a column count of 2 which is what I expect, but the 2nd msgbox (with title after) displays a column count of 3 which is not really what I expect.

I understand why field3 is in my dataset after the fill (because it is included in the SELECT statement), but I am hoping that there is a way to prevent the structure of the dataset to be changed as a result of the Fill().

Einar
Semper ubi sub ubi.
Next
Reply
Map
View

Click here to load this message in the networking platform