我试图填充使用一种叫做PopulateGrid(法)一个GridView(下同),但继续得到同样的服务器错误的标量变量“必须声明标量变量‘@QUALID’。ASP.NET C#必须声明
public void PopulateGrid()
{
String val = TextBox2.Text;
String sql = "SELECT QLEVELNAME FROM Qual_Levels WHERE [email protected]";
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控件被宣布像这样..
<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>
尝试了无数的东西,通过我一直来面对同样的错误论坛拖网后。
Server Error in '/' Application.
Must declare the scalar variable "@QUALID".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@QUALID".
Source Error:
Line 282: DataSet ds = new DataSet();
Line 283: da.Fill(ds, "Qual_Levels");
如果任何人都可以摆脱这种情况,我会非常感激!
感谢所有的答复,一般的共识似乎是我”在我的SQL参数中错过了@但尝试过了,并且抛出了相同的错误。此外,我拥有完全相同的语法,最初发布为我的下拉列表工作正常。 – PatrickJames 2012-03-06 14:48:14