如何删除一行数据

cetfyg 2008-05-21 10:26:11
已经得到要删除行的ID(有两个ID,ID1和ID2)和表名"nodeinfo",在C# 中怎样用SQL语句实现在数据库中删除该行?
...全文
96 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljm66 2008-05-21
  • 打赏
  • 举报
回复
string StrSql = "delete from nodeinfo where ID = ID1 or ID = ID2 ";
baihe_591 2008-05-21
  • 打赏
  • 举报
回复
SqlConnection conn=new SqlConnection ("打开数据库sql语句");
SqlCommand comm = new SqlCommand("Delete from nodeinfo where ID='ID1'", conn);
comm.Connection.Open();
comm.ExecuteNonQuery();
saluter99 2008-05-21
  • 打赏
  • 举报
回复
对了,我用的ODBC.NET,你可能不需要,就把 Microsoft.Data.Odbc.去了就行了
saluter99 2008-05-21
  • 打赏
  • 举报
回复
我自己用的ODBC连接的例子,用别的连接方法改一下就行了

//定义LOG库的ODBC数据源
string strODBCConnection = "Driver={SYBASE SYSTEM 11};Srvr=" +
server + ";Uid=" +
uid + ";Pwd=" +
pwd + ";DB=" +
dbase;
string StrSql = "delete from nodeinfo where ID1 = value and ID2 = Value";
Microsoft.Data.Odbc.OdbcConnection myConn = new Microsoft.Data.Odbc.OdbcConnection(strODBCConnection);
Microsoft.Data.Odbc.OdbcCommand myCmd = new Microsoft.Data.Odbc.OdbcCommand(StrSql, myConn);
myConn.Open();
int IntReturn = myCmd.ExecuteNonQuery();
myConn.Close();
Tll_W 2008-05-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 baihe_591 的回复:]
SqlConnection conn=new SqlConnection ("打开数据库sql语句");
SqlCommand comm = new SqlCommand("Delete from nodeinfo where ID='ID1'", conn);
comm.Connection.Open();
comm.ExecuteNonQuery();
[/Quote]

跟查询、修改语句差不多。。就不重复贴代码了
阿建像熊猫 2008-05-21
  • 打赏
  • 举报
回复
长的像陈真~!
cetfyg 2008-05-21
  • 打赏
  • 举报
回复
这不管用,试过了.我把应该把代码附上,让大家看看

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧