Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
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'
Posted
v3

1 solution

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.
 
Share this answer
 
Comments
Member 10744248 13-Jun-14 23:52pm    
DataTable dt = ds.Tables[0];

what does 'ds.Tables[0]' mean
Nirav Prabtani 14-Jun-14 1:40am    
it means datatable of dataset having index 0,
Dataset is collection of multiple datatables there can be table[0],table[1],table[2]...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900