Reputation: 17493
When checking the official documentation about System.Data.DataSet
and System.Data.DataTable
, I have the impression that "importing an MS-SQL table into C# classes" happens as follows:
SqlCommand
, containing the name of the table, the names of the columns: SELECT ProductID, SupplierID FROM dbo.Products
(or SELECT *
), but still the corresponding SqlDataReader
must be run through for getting the values inside the table).Isn't there some way to say:
DataTable dt_Products = new DataTable(connection, "Products")
... and this DataTable
automatically has the right column names, column types, values, autoincrement properties if possible, ... (without needing to pass by SqlCommand
, SqlDataReader
, ...)?
Upvotes: 0
Views: 478
Reputation: 71
Maybe what you need is this.
using (var da = new System.Data.SqlClient.SqlDataAdapter("SELECT ProductID, SupplierID FROM dbo.Products", connection))
{
da.Fill(dt_Products);
}
Upvotes: 1