我想使用 select WHERE 语句从名为 hotel 的 sql server 表中检索数据,但出现上述错误。任何人都可以帮忙吗?
SqlConnection cnn = new
SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ToString());
cnn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT RoomsAvailable FROM Hotel WHERE HotelName = '" +
this.DropDownList1.Text + "'";
cmd.Connection = cnn;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "Hotel");
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataRow dsRow = null;
foreach (DataRow dsRow_loopVariable in ds.Tables["Hotel"].Rows)
{
dsRow = dsRow_loopVariable;
//This line is where the error comes in.
this.txtHotel.Text = (dsRow["RoomsAvailable"]);
}