本文介绍了获取SQL错误我该怎么做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此代码我仍然收到错误
异常抛出:System.Data.dll中的'System.Data.SqlClient.SqlException'
附加信息:')'附近的语法不正确。
With this codes I m still getting error
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
Additional information: Incorrect syntax near ')'.
<pre lang="text"> private void insert_Click(object sender, RoutedEventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand (@"Insert into mob (FirstName, LastName, Mobile, emailid, Category) VALUES
('"+ First.Text + "','" + Last.Text +"','" + Mobile.Text +"', '" + email.Text + "','" +comboBox + "',)", con);
cmd.ExecuteNonQuery();
con.Close();
}
推荐答案
SqlCommand cmd = new SqlCommand (@"Insert into mob (FirstName, LastName, Mobile, emailid, Category) VALUES
('"+ First.Text + "','" + Last.Text +"','" + Mobile.Text +"', '" + email.Text + "','" +comboBox + "')", con);
注意:您的代码容易受到SQL注入攻击。我强烈建议使用参数化查询或存储过程。
参考:
[]
希望,它有帮助:)
Note: Your code is vulnerable to SQL Injection. I strongly recommend to use Parameterized Query or Stored Procedure instead.
Reference:
Using Parameterized queries to prevent SQL Injection Attacks in SQL Server[^]
Hope, it helps :)
这篇关于获取SQL错误我该怎么做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!