我正在尝试在运行时传递要在代码中检查的列名和值。但是我得到一个“无效的列名”异常。代码如下:
string temp = TextBox1.Text.ToString();
SqlConnection con = new SqlConnection("data source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Sagar\\Documents\\Test.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand com = new SqlCommand("Select * from Employee Where @field = Sagar", con);
com.Parameters.AddWithValue("@field", DropDownList1.SelectedValue.ToString());
//com.Parameters.AddWithValue("@value", temp);
SqlDataAdapter da = new SqlDataAdapter(com);
con.Open();
SqlDataReader reader = com.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();