我正在尝试使用 SqlConnection 获取我在我的存储过程中使用的输出参数的值,但我没有得到,努力但没有弄清楚我在哪里做错了,程序没有给出任何错误,但在结束 _clientCode 的值变空。
我需要你们的支持,请帮我找出我需要改变的地方
谢谢,
as you can see in the image as I attached.
public string getData5(string icuser) {
string _clientCode;
SqlDataReader dataReader;
{
SqlConnection conn = new SqlConnection();
SqlCommand command = new SqlCommand();
conn.ConnectionString = "Server=xxx-dbprod;DataBase=TCS;Integrated Security=True;";
// conn.ConnectionString = "Data Source = tcr-dbprod; Initial Catalog = TCS; Integrated Security = True;";
//conn.ConnectionString = ConfigurationManager.ConnectionStrings["CS"].ConnectionString;
command.Connection = conn;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "[dbo].[spTCRGetClientCode]";
command.Parameters.AddWithValue("@icUserID", icuser);
command.Parameters.Add(new SqlParameter("@clientCode", SqlDbType.NVarChar, 300));
command.Parameters["@clientCode"].Direction = ParameterDirection.Output;
try
{
conn.Open();
int i = command.ExecuteNonQuery();
dataReader = command.ExecuteReader();
_clientCode = Convert.ToString(command.Parameters["@clientCode"].Value);
conn.Close();
return _clientCode;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
//conn.Close();
//DbConnection.Dispose();
}
}
}
我在我的问题详细说明中解释并附上截图以供您帮助。