gpt4 book ai didi

c# - asp.net 错误 : Cannot implicitly convert type 'object' to 'string' . 存在显式转换(是否缺少强制转换?)

转载 作者:行者123 更新时间:2023-11-30 13:58:05 25 4
gpt4 key购买 nike

我想使用 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"]);
}

最佳答案

改变

this.txtHotel.Text = (dsRow["RoomsAvailable"]);

this.txtHotel.Text = (dsRow["RoomsAvailable"].ToString());

关于c# - asp.net 错误 : Cannot implicitly convert type 'object' to 'string' . 存在显式转换(是否缺少强制转换?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18468046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com