ASP.NET C# Must declare the scalar variable

后端 未结 6 1813
一生所求
一生所求 2021-01-17 23:56

I am trying to populate a GridView using a method called PopulateGrid() (below) but keep getting the same server error "Must Declare the scalar variable "@QUALID&q

6条回答
  •  Happy的楠姐
    2021-01-18 00:30

    This:

    cmd.Parameters.Add(new SqlParameter("QUALID", val));
    

    should be this:

    cmd.Parameters.Add(new SqlParameter("@QUALID", val));
    

    Sorry, typed too quick, try:

    cmd.Parameters.AddWithValue("@QUALID", val);
    

    OK, you have a slightly more fundamental issue in your code. You create a command object, but then you pass the SQL string and the connection for the command into your dataadapter, where it will execute your sql string with no parameters on it's connection.

    I haven't used dataadapters too much, but I think you need to set the parameters on the select command of your adapter.

提交回复
热议问题