请澄清以下'param1' [英] Pls clarify the following 'param1'

查看:111
本文介绍了请澄清以下'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 parameter POSITION_CODE, which you are passing by that block of code.

The value for this parameter is Session["selected_position_code"].

After adding the parameter, you are getting the data as a Table with the help of DataAdapter, which binds to a DataTable dt.


这篇关于请澄清以下'param1'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆