【发布时间】:2014-01-28 10:51:40
【问题描述】:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=HKGROX-PC\\SQLEXPRESS;Initial Catalog=example;Integrated Security=True");
con.Open();
string value = DropDownList1.SelectedValue.ToString();
switch (value)
{
case "BJP":
string s = "select BJP from noofvotes where year= "+ DropDownList2.Text+" and const=" + DropDownList3.SelectedValue + "";
SqlCommand cmd = new SqlCommand(s,con);
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
DataRow dr = ds.Tables[0].Rows[0];
TextBox1.Text = dr["BJP"].ToString();
}
break;
}
con.Close();
}
在这里我得到无效的列名“Rohini”。我有一个将值提供给列表框的表格。
【问题讨论】:
-
YEAR 是保留关键字。你的表的真实列名是什么?
-
您在哪里看到此错误?这段代码中没有提到
Rohini? -
我想
DropDownList3.SelectedValue包含值“Rohini”,它没有被''包围,所以它被解释为一个列(where const=Rohini)。按照@Steve 的建议使用参数。
标签: c#