Dominique
Dominique

Reputation: 17493

Simple import of an MS-SQL table into System.Data.DataTable, is this possible?

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:

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

Answers (1)

Lin Yi-Sheng
Lin Yi-Sheng

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

Related Questions