无法将类型“System.Data.SqlClient.SqlDataReader”隐式转换为“System.DateTime”
DateTimeres;stringmycnn="DataSource=.;InitialCatalog=HotelReservation;IntegratedSecur...
DateTime res;
string mycnn = "Data Source=.;Initial Catalog=HotelReservation;Integrated Security=True";
SqlConnection myconnection = new SqlConnection(mycnn);
string str = "select Max(Outtime) from Dingdan where Room='"+ DropDownList2.SelectedItem.Value+"'";
SqlCommand mycommand = new SqlCommand(str,myconnection);
mycommand.Connection.Open();
SqlDataReader myreader = mycommand.ExecuteReader();
if (myreader.Read())
{
res = mycommand.ExecuteReader();
}
else
{
Page.RegisterStartupScript("", "<script>alert('该房间在该时间已经被预定!')</script>");
mycommand.Connection.Close();
}
return res; 展开
string mycnn = "Data Source=.;Initial Catalog=HotelReservation;Integrated Security=True";
SqlConnection myconnection = new SqlConnection(mycnn);
string str = "select Max(Outtime) from Dingdan where Room='"+ DropDownList2.SelectedItem.Value+"'";
SqlCommand mycommand = new SqlCommand(str,myconnection);
mycommand.Connection.Open();
SqlDataReader myreader = mycommand.ExecuteReader();
if (myreader.Read())
{
res = mycommand.ExecuteReader();
}
else
{
Page.RegisterStartupScript("", "<script>alert('该房间在该时间已经被预定!')</script>");
mycommand.Connection.Close();
}
return res; 展开
展开全部
if (myreader.Read())
{
res = mycommand.ExecuteReader();
}
修改 res=myreader.GetDateTime(int i); i为取得的索引号
{
res = mycommand.ExecuteReader();
}
修改 res=myreader.GetDateTime(int i); i为取得的索引号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//改为
if (myreader.Read())
{
res = DateTime.Parse(myreader["数据库中要查询的列名"]);
}
//最后要加myreader.Close();
if (myreader.Read())
{
res = DateTime.Parse(myreader["数据库中要查询的列名"]);
}
//最后要加myreader.Close();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询