ASP.NET C# Must declare the scalar variable

后端 未结 6 1772
一生所求
一生所求 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条回答
  •  逝去的感伤
    2021-01-18 00:32

    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));
    SqlDataAdapter da = new SqlDataAdapter(sql, cmd.Connection);
    DataSet ds = new DataSet();
    cmd.Parameters.Add(new SqlParameter("@QUALID", val));
    
    da.SelectCommand = cmd;
    cmd.Connection.Open();
    
    da.Fill(ds, "Qual_Levels");
    
    
    SelectionGrid.DataSource = ds;
    SelectionGrid.DataBind();
    
    ds.Dispose();
    da.Dispose();
    cmd.Connection.Close();
    cmd.Connection.Dispose();
    

    use dis one it will work...(da.selectcommand = cmd;)

提交回复
热议问题