从sql数据库表中删除数据 [英] delete data from sql database table
问题描述
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=d:\users\vivek\documents\visual studio 2010\Projects\soft\soft\database\vks.mdf;Integrated Security=True;User Instance=True";
string str;
str = "insert into qualification_master (qualification_name) values(''" + comboBox1.Text + "'')";
con.Open();
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
上面的代码中用于删除数据的内容有什么变化?
what change in above code for delete data ?
推荐答案
首先,使用代码块格式化代码.
其次,使用参数化查询,您的代码容易受到SQL Injection攻击.
这就是答案.
First, format your code using code blocks.
Second, use parameterized queries, your code is susceptible to SQL Injection attacks.
Here is the answer.
DELETE FROM qualification_master WHERE qualification_name = @yourValue
好像您对sql查询一无所知. >
Looks like you have no idea about sql queries.
str = "DELETE FROM qualification_master WHERE qualification_name = ''" + comboBox1.Text + "''";
如果表中有主键,则必须在where条件下使用它.
选中此项以进行删除查询.
http://www.w3schools.com/sql/sql_delete.asp [此处开始 [
If you have primary key in table, you have to use that in where condition.
Check this for delete query.
http://www.w3schools.com/sql/sql_delete.asp[^]
To learn sql start from here[^].
DELETE FROM qualification_master
相信我,这将从表中删除所有数据.不要使用
Trust me this will delete all the data from table. Don''t use
Where
子句,切勿在.Net中使用参数化查询.
请大家不要发布这些类型问题的答案.
这个家伙甚至都不知道SQL命令,我们如何帮助这个家伙?
他想要有关SQL的帮助(主题:删除数据)具有C#标签.
clause and never use parametrized query in .Net.
Please guys don''t post answer to these type questions.
This guy even don''t know the SQL command, how can we help this guy?
He want help on SQL (subject: delete data) has a tag of C#.
这篇关于从sql数据库表中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!