请澄清以下'param1' [英] Pls clarify the following 'param1'
本文介绍了请澄清以下'param1'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void GetPositionName(字符串 PosCode)
{
如果(cn.State == ConnectionState.Open)
{
cn.Close();
}
cn.Open();
lblConnectionState.Text = CONNECTED;
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = GET_POSITION_NAME;
SqlParameter param1 = new SqlParameter();
param1.ParameterName = POSITION_CODE;
param1.Direction = ParameterDirection.Input;
param1.SqlDbType = SqlDbType.VarChar;
param1.Value = PosCode;
param1.Value =会话[ selected_position_code];
cmd.Parameters.Add(param1);
da.SelectCommand = cmd;
da.Fill(ds);
DataTable dt = ds.Tables [ 0 ];
lblPositionName.Text = dt.Rows [ 0 ] [ POSITION_NAME]。ToString( );
}
请澄清代码的粗体部分SqlParameter和param1
解决方案
您的存储过程需要参数POSITION_CODE
,您将通过该代码块传递。
此参数的值为Session [selected_position_code]
。
添加参数后,在DataAdapter
的帮助下将数据作为表获取,它绑定到DataTable
DT
public void GetPositionName(string PosCode)
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
cn.Open();
lblConnectionState.Text = "CONNECTED";
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GET_POSITION_NAME";
SqlParameter param1 = new SqlParameter();
param1.ParameterName = "POSITION_CODE";
param1.Direction = ParameterDirection.Input;
param1.SqlDbType = SqlDbType.VarChar;
param1.Value = PosCode;
param1.Value = Session["selected_position_code"];
cmd.Parameters.Add(param1);
da.SelectCommand = cmd;
da.Fill(ds);
DataTable dt = ds.Tables[0];
lblPositionName.Text = dt.Rows[0]["POSITION_NAME"].ToString();
}
Kindly clarify the boldened portion of the codes "SqlParameter" and 'param1'
解决方案
Your Stored Procedure expects parameterPOSITION_CODE
, which you are passing by that block of code.
The value for this parameter isSession["selected_position_code"]
.
After adding the parameter, you are getting the data as a Table with the help ofDataAdapter
, which binds to aDataTable
dt
.
这篇关于请澄清以下'param1'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文