我正在通过一个带有各种参数的对象向 SQL 发送,并且需要返回一个 0 或 1 的值,以指示成功或失败。
我已经确认我的所有参数都已成功发送到 SQL,但我遇到了关于需要返回到 C# 的“@Result”值的问题。
这是我在 Data.cs 文件中的代码摘录:
public System.Data.DataSet spe_ISUpgradePossible(dbObject currentDBObj)
{
using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionString))
{
using (System.Data.SqlClient.SqlCommand command = GetCommand("spe_ISUpgradePossible", connection))
{
command.CommandType = System.Data.CommandType.StoredProcedure;
System.Data.SqlClient.SqlParameter parameter;
parameter = new System.Data.SqlClient.SqlParameter("@ServicePack", System.Data.SqlDbType.NVarChar);
parameter.Direction = System.Data.ParameterDirection.Input;
parameter.Value = currentDBObj.servicePack;
command.Parameters.Add(parameter);
parameter = new System.Data.SqlClient.SqlParameter("@ServicePackFolder", System.Data.SqlDbType.NVarChar);
parameter.Direction = System.Data.ParameterDirection.Input;
parameter.Value = currentDBObj.servicePackFolder;
command.Parameters.Add(parameter);
parameter = new System.Data.SqlClient.SqlParameter("@Result", System.Data.SqlDbType.Int);
parameter.Direction = System.Data.ParameterDirection.Output;
command.Parameters.Add(parameter);
System.Data.DataSet dataSet = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(command);
adapter.Fill(dataSet);
return dataSet;
//int result = Convert.ToInt16(command.Parameters["@Result"].Value.ToString());
//return result;
}
}
}
我添加了以下两行来满足“@Result”:
//int result = Convert.ToInt16(command.Parameters["@Result"].Value.ToString());
//return result;
这导致显示以下错误:“无法将类型 'int' 隐式转换为 'System.Data.Dataset'”
有人可以帮助我解决上述问题吗?任何援助将不胜感激。