我有接收sql字符串的DataSet方法,如下:
public DataSet GetDataSet(string sql, string TableName)
{
this._Errors = false;
SqlDataAdapter da = new SqlDataAdapter(sql.ToString(), this.dbconn);
da.SelectCommand.CommandTimeout = 0;
DataSet ds = new DataSet();
try
{
da.Fill(ds, TableName);
return ds;
}
catch (SqlException e)
{
this.HandleSQLError(e, "GetDataSet", sql);
return null;
}
}这可以正常工作,但是现在我想在sql中以Table Variable的形式发送DataTable来接收。
使用SqlCommand很简单,如下所示:
SqlCommand cmd = new SqlCommand(sprocName, this.dbconn);
cmd.Parameters.Add(new SqlParameter(customerTypeTableName, SqlDbType.Structured));
cmd.Parameters[customerTypeTableName].Value = customerTypeList;如何修改才能使用SqlAdapter方法做同样的事情?问候
发布于 2019-05-26 15:55:13
我想你应该写一个新的函数。不需要使用DataAdapter。一个SqlCommand类型的对象就足够了,如以下代码片段所示。
comm.Parameters.AddWithValue("@tvpEmails", dt); // dt is your DataTable
// your UDDT type should exist on your SQL instance under UDDT types
comm.Parameters[comm.Parameters.Count - 1].TypeName = "your UDDT type";
comm.Parameters[comm.Parameters.Count - 1].SqlDbType = SqlDbType.Structured;
comm.ExecuteNonQuery();https://stackoverflow.com/questions/56299956
复制相似问题