Asp.net 删除数据库中的一行数据应该怎么写 他说我有语法错误
2个回答
展开全部
你用的是什么数据库啊,如果是SQL的话
SqlConnection conn = new SqlConnection("") ///数据库连接字符串
string sql = string,Format("update dbo set ('{0}','{1}','{2}','{3}') where ID= '{4}'",bookName,bookPrice,chubanshe,date);
SqlCommand cmd = new SqlCommand(sql,conn);
int result = cmd.ExecuteNonQuery;//影响行数
if(result != null)
{Console.WriteLine("更新成功");}
else{Console.WriteLine("更新失败");}
删除的话把语句换成"delete from dbo where ID= '{0}'",bookID
添加:"insert into dbo values('{0}','{1}','{2}','{3}')",bookName,bookPrice,chubanshe,date
SqlConnection conn = new SqlConnection("") ///数据库连接字符串
string sql = string,Format("update dbo set ('{0}','{1}','{2}','{3}') where ID= '{4}'",bookName,bookPrice,chubanshe,date);
SqlCommand cmd = new SqlCommand(sql,conn);
int result = cmd.ExecuteNonQuery;//影响行数
if(result != null)
{Console.WriteLine("更新成功");}
else{Console.WriteLine("更新失败");}
删除的话把语句换成"delete from dbo where ID= '{0}'",bookID
添加:"insert into dbo values('{0}','{1}','{2}','{3}')",bookName,bookPrice,chubanshe,date
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询