方法执行存储过程并返回C#中的数据表
本文关键字:数据表 返回 执行 存储过程 方法 | 更新日期: 2023-09-27 18:20:53
我有一些VB代码,比如
Dim data As DataTable = DataAccess.ExecuteDataSet("AuthenticateWebServiceClient" _
, New SqlParameter("@ClientID", ClientId) _
, New SqlParameter("@Password", Password) _
, New SqlParameter("@WebServiceID", WebServiceID)).Tables(0)
和一个具有此功能的DataAccess类
Public Shared Function ExecuteDataSet(ByVal storedProcName As String, ByVal ParamArray parameters As SqlParameter()) As DataSet
'Try
Dim command As SqlCommand = PrepareSPCommand(storedProcName, parameters)
Dim adapter As New SqlDataAdapter(command)
Dim ds As New DataSet
adapter.Fill(ds)
Return ds
'Catch ex As Exception
'ex.ToString()
'End Try
End Function
当我试图通过转换器将其转换为C#时,我会得到
private DataSet ExecuteDataSet(string storedProcName, SqlParameter[] parameters)
{
SqlCommand command = PrepareSPCommand(storedProcName, parameters);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
除了PrepareSPCommand不被VS识别。有人知道将此函数转换为C#的正确方法吗。
此处,
public SqlCommand PrepareSPCommand(string storedProcName, SqlParameter[] parameters, string connectionString){
SqlCommand command = new SqlCommand(storedProcName,new SqlConnection(connectionString));
command.CommandType=CommandType.StoredProcedure;
command.Parameters.AddRange(parameters);
return command;
}
当然。与VB.net 相比,C#没有什么神秘之处
DataTable data = DataAccess.ExecuteDataSet("AuthenticateWebServiceClient", New SqlParameter("..."), etc).Tables[0];