一次删除数据库行 [英] delete database row at once

查看:53
本文介绍了一次删除数据库行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单击时删除数据库行我的代码无效。



how to delete database row at single click my code didnt work.

  protected void Delete_Click(object sender, EventArgs e)

{
SqlConnection conn = new     SqlConnection(ConfigurationManager.ConnectionStrings["registrationConnectionString"].ConnectionString);
string sqlStatement = "DELETE * userdata";
SqlCommand com = new SqlCommand(sqlStatement, conn);
conn.Close();
           
}

推荐答案

对于一个不会删除行但是每一行的开始。



你没打电话



Well for a start that is not going to delete a row, but every row.

And you're not calling

com.ExecuteNonQuery();





进行实际执行。



to do the actual execution.


string sqlStatement =DELETE * userdata ;





你可以使用



string sqlStatement =DELETE From tableName;

(或)

string sqlStatement =DELETE From userdata;
string sqlStatement = "DELETE * userdata";


you can use

string sqlStatement = "DELETE From tableName";
(or)
string sqlStatement = "DELETE From userdata";


I guess you want to delete all rows from table so correct the command first as
<pre lang="c#">protected void Delete_Click(object sender, EventArgs e)

{
SqlConnection conn = new     SqlConnection(ConfigurationManager.ConnectionStrings["registrationConnectionString"].ConnectionString);
string sqlStatement = "DELETE * from  userdata";
SqlCommand com = new SqlCommand(sqlStatement, conn);
cmd.ExecuteNonQuery();//have to execute above command query
conn.Close();

}</pre>

Reply if any query or mark as solution


这篇关于一次删除数据库行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆