我无法纠正以下错误:System.Data.SqlClient.SqlException(0x80131904):无效的列名'OAT'

问题描述 投票:0回答:1
protected void btnDeleteVenue_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                string ddl = DropDownList1.SelectedItem.Value;
                string sq = "select venue_name from Venue";
                cmd = new SqlCommand(sq, con);
                SqlDataReader r = cmd.ExecuteReader();
                string dq = null;
                if (r.HasRows)
                {
                    while (r.Read())
                    {
                        if (ddl.Equals(r.GetValue(0).ToString()))
                        {
                           string dq = "DELETE from Venue WHERE venue_name=" + ddl;
                            //.Close();
                            cmd = new SqlCommand(dq, con);
                            cmd.ExecuteNonQuery();
                            Response.Write("<script> alert('Venue Deleted') </script>");
                            con.Close();
                        }
                    }
                }

            }
            catch(Exception ex)
            {
                Response.Write(ex);
            }
        }
c# sql-server visual-studio
1个回答
0
投票

将此行更改为。必须用引号引起来。

string dq = "DELETE from Venue WHERE venue_name='" + ddl + "'";
热门问题
推荐问题
最新问题