Why is there no default name for a DataTable here adapter.Fill(dt);

T

Tony

Here I have a simple example. If I use alternative 2 where a dataset is used
in this code the default table name is called Table which is correct.
But if I use alternative 1 where a DataTable is used instead then the
DataTable are not given any default name Why ?

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);

string strSQL = "Select OrderID, Quantity, unitPrice from [Order
Details]";

SqlDataAdapter adapter = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
1 // adapter.Fill(dt);
2 adapter.Fill(ds);
}

//Tony
 
A

Arne Vajhøj

Here I have a simple example. If I use alternative 2 where a dataset is
used in this code the default table name is called Table which is correct.
But if I use alternative 1 where a DataTable is used instead then the
DataTable are not given any default name Why ?

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);

string strSQL = "Select OrderID, Quantity, unitPrice from [Order Details]";

SqlDataAdapter adapter = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
1 // adapter.Fill(dt);
2 adapter.Fill(ds);
}

The MS developer designing this many years ago may have
considered it unimportant to have a name when you only have
one table.

Arne
 
R

Registered User

Here I have a simple example. If I use alternative 2 where a dataset is used
in this code the default table name is called Table which is correct.
But if I use alternative 1 where a DataTable is used instead then the
DataTable are not given any default name Why ?

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);

string strSQL = "Select OrderID, Quantity, unitPrice from [Order
Details]";

SqlDataAdapter adapter = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
1 // adapter.Fill(dt);
2 adapter.Fill(ds);
}

MSDN is an excellent resource. The various overloads of the method
SqlDataAdapter.Fill are listed at
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.fill.aspx
Follow the appropriate links for detailed information.

regards
A.G.
 

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