-2

AM TRYING TO DISPLAY A GRIDVIEW WITH THE GIVEN INFORMATION FROM THE DATABASE AND STORED PROCEDURE

C# code:

protected void Page_Load(object sender, EventArgs e)
{ 
    if (!IsPostBack)
    {
        GridView1.AllowPaging = true;
        GridView1.PageSize = 15;
        GridView1.AllowSorting = false;

        BindGridView();
    }
}

private void BindGridView()
{
    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["VOICE"].ToString()))
    {
        DataSet leo = new DataSet();

        string strSelectCmd = "usp_checklist_select";

        SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, conn);

        conn.Open();

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "UPDATE usp_checklist_select SET task_system = @System";
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.Add("@System", SqlDbType.Char, 3);

        da.Fill(leo, "usp_checklist_select");

        DataView list = leo.Tables["usp_checklist_select"].DefaultView;
        GridView1.DataSource = list;
        GridView1.DataBind();
    }
}

Stored procedure:

ALTER PROCEDURE [dbo].[usp_checklist_select]
    @System CHAR(3) 
AS
BEGIN
    SET NOCOUNT ON;

    SELECT
        [task_id],
        [task_system],
        [task_time],
        [task_name],
        [task_status],
        [task_sched],
        [task_comment],
        [task_startendmonth],
        [task_hreflink],
        [task_signedoffby],
        [task_signedoffdatetime]
    FROM 
        [dbo].[checklist_master]
    WHERE 
        task_system = @System
END
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

your problem is this line of code

cmd.Parameters.Add("@System", SqlDbType.Char, 3);

you basically just tell the command that it should expect a parameter called '@System' of type 'char' and a size (length) of three - you do not actually pass the parameters value and recieve the error above.

try

cmd.Parameters.Add("@System", SqlDbType.Char).Value = 3;
Sancho Panza
  • 670
  • 4
  • 11