sqlexception是unhandle [英] sqlexception was unhandle

查看:108
本文介绍了sqlexception是unhandle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是...........

my code is...........

{
    SqlConnection con = new SqlConnection("Data Source=RAMESH-PC;Initial Catalog=edburg;Integrated Security=True;Pooling=False");
    con.Open();
    SqlCommand cm = new SqlCommand("insert into table(name,num,sal,phone)  values('" + textBox1.Text + "'," + textBox2.Text + "," + textBox3.Text + "," + textBox4.Text + ")", con);
    MessageBox.Show(cm.ExecuteNonQuery().ToString());
    con.Close();
}



错误:关键字''table''附近的语法不正确。

推荐答案

首先,你不应该使用关键字 [ ^ ]类似于表名的''table''。



其次,看起来tablename之后没有空格。

尝试:

Firstly, you should not use keywords[^] like ''table'' for a table name.

Secondly, it looks like there is no space after tablename.
Try:
SqlCommand cm = new SqlCommand("insert into myTable (name,num,sal,phone)  values('" + textBox1.Text + "'," + textBox2.Text + "," + textBox3.Text + "," + textBox4.Text + ")", con);





第三,在查询中直接传递控件值是不好的做法。这可能会导致SQL注入。请阅读以下有关保护SQL注入的信息: SQL注入缓解:使用参数化查询 [ ^ ]


您还没有输入表名...正确的陈述是



插入到actual_tablename(.....)值(...)



由于表格是关键字,所以它抛出错误...所以用实际的表名替换表。
You''ve not entered the table name...the right statement is

insert into actual_tablename (.....) values(...)

Since table is the keyword, so it is throwing the error... so replace table with actual table name.


这篇关于sqlexception是unhandle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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