使用存储过程在数据集中填充自定义 table

Filling custom table in dataset with stored procedure

正如我上面的问题,我想在数据集中创建一个自定义数据表(我的意思是我不将 .MDF 文件中的现有数据表或视图拖放到数据集中)并用存储的数据填充它程序。有什么办法吗?请给我任何参考 link 或教程。 有关更多信息,我正在使用 LinQ to SQL 来处理我的数据库 感谢和问候

使用 SqlDataAdapter to fill the table. Set it's SelectCommand's CommandTypeCommandType.StoredProcedure:

DataTable dt = new DataTable("Optional TableName");
using (var con = new SqlConnection("Connection-String Here"))
using (var da = new SqlDataAdapter("StoredProcedureName", con))
{
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    // you don't need to open/close the connection with Fill
    da.Fill(dt);
    dataSet.Tables.Add(dt);
}