I am trying to populate the GridView using the PopulateGrid () method (see below), but keep getting the same server error "Must declare scalar variable" @QUALID ".
public void PopulateGrid()
{
String val = TextBox2.Text;
String sql = "SELECT QLEVELNAME FROM Qual_Levels WHERE QUALID=@QUALID";
SqlCommand cmd = new SqlCommand(sql,
new SqlConnection(ConfigurationManager.ConnectionStrings["RecruitmentDBConnString"].ConnectionString));
cmd.Parameters.Add(new SqlParameter("QUALID", val));
cmd.Connection.Open();
SqlDataAdapter da = new SqlDataAdapter(sql, cmd.Connection);
DataSet ds = new DataSet();
da.Fill(ds, "Qual_Levels");
SelectionGrid.DataSource = ds;
SelectionGrid.DataBind();
ds.Dispose();
da.Dispose();
cmd.Connection.Close();
cmd.Connection.Dispose();
}
GridView is declared like this.
<asp:GridView ID="SelectionGrid"
autogeneratecolumns="False"
runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" DataKeyNames="QUALID">
<Columns>
<asp:BoundField DataField="QLEVELNAME" HeaderText="Level Name"
ReadOnly="True" SortExpression="name" />
</Columns>
</asp:GridView>
After trying countless things and going through the forums, I continue to encounter the same error.
Server error in application "/".
Must declare the scalar variable "@QUALID".
Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for error information and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: The scalar variable "@QUALID" must be declared.
Source Error:
Line 282: DataSet ds = new DataSet ();
283: da.Fill(ds, "Qual_Levels" );
- , !