怎样用asp.net语句删除数据库中某一条记录啊?
数据库名称:hotel表名:DingfangStringconstr="DataSource=.;InitialCatalog=hotel;IntegratedSecur...
数据库名称:hotel
表名:Dingfang
String constr = "Data Source=.;Initial Catalog=hotel;Integrated Security=True";
SqlConnection conn = new SqlConnection(constr);
conn.Open();
//客房入住
String RoomId = TextBox1.Text;
String ClientName = TextBox2.Text;
String ClientId = TextBox3.Text;
String CheckinTime = TextBox4.Text;
String PresentTime = TextBox5.Text;
String CheckinPrice = TextBox6.Text;
String SqlCheckOut = "DELETE FROM Dingfang where RoomId='" + RoomId + "'and ClientName='" + ClientName + "' and ClientId='" + ClientId + "' and CheckinTime='" + CheckinTime + "' and PresentTime='" + PresentTime + "' and CheckinPrice='" + CheckinPrice + "'";
SqlCommand CmdCheckOut = new SqlCommand(SqlCheckOut, conn);
CmdCheckOut.ExecuteNonQuery();
我想让入住记录删除一个,但是这样写无效,要不就是删除整个Dingfang表中的数据。
请问我怎样才可以删除? 展开
表名:Dingfang
String constr = "Data Source=.;Initial Catalog=hotel;Integrated Security=True";
SqlConnection conn = new SqlConnection(constr);
conn.Open();
//客房入住
String RoomId = TextBox1.Text;
String ClientName = TextBox2.Text;
String ClientId = TextBox3.Text;
String CheckinTime = TextBox4.Text;
String PresentTime = TextBox5.Text;
String CheckinPrice = TextBox6.Text;
String SqlCheckOut = "DELETE FROM Dingfang where RoomId='" + RoomId + "'and ClientName='" + ClientName + "' and ClientId='" + ClientId + "' and CheckinTime='" + CheckinTime + "' and PresentTime='" + PresentTime + "' and CheckinPrice='" + CheckinPrice + "'";
SqlCommand CmdCheckOut = new SqlCommand(SqlCheckOut, conn);
CmdCheckOut.ExecuteNonQuery();
我想让入住记录删除一个,但是这样写无效,要不就是删除整个Dingfang表中的数据。
请问我怎样才可以删除? 展开
3个回答
展开全部
0.0
delete [table] where [条件]
例如
delete [table] where ( id = 1 )
delete [table] where [条件]
例如
delete [table] where ( id = 1 )
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把你SQL语句内的and 换成OR 试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
where 跟一个唯一键即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询