缺少分号(;)C# [英] Missing semicolon (;) C#

查看:192
本文介绍了缺少分号(;)C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将数据插入访问数据库时,我收到错误。

在sql语句结束时缺少分号(;)...

any可以帮帮我吗?

ps我试着把分号放到最后但同样错误..

插入命令在这里:





 oleDbDataAdapter1.InsertCommand.CommandText = 
< span class =code-string> insert into magazina(sasia)values(' + sasia_totale + ')其中emri =' + listBox1.SelectedItem + ';
oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();

解决方案

太多双引号!

更改:

 oleDbDataAdapter1.InsertCommand.CommandText = 
插入magazina(sasia)值(' + sasia_totale + ')其中emri =' + listBox1.SelectedItem + ' ;

To :

 oleDbDataAdapter1.InsertCommand.CommandText = 
插入magazina(sasia)值(' + sasia_totale + ')其中emri =' + listBox1.SelectedItem + ';


< blockquote>你不能将WHERE子句与INSERT语句一起使用。



我认为你需要将此查询更改为UPDATE语句。



另外,你应该谷歌为SQL注入攻击找出为什么使用字符串连接来构建你的SQL语句是一个可怕的想法,你可以做些什么来解决它。另一个谷歌搜索将是C#SQL参数化查询。


尝试以下一个:



 oleDbDataAdapter1.InsertCommand.CommandText = 
插入magazina(sasia)值(' + sasia_totale + ')
其中emri ='
+ listBox1.SelectedItem + ';





我希望这会对你有所帮助。


I'm getting error when i try to insert data into a access database..
missing semicolon (;) at the end of sql statement..
anyone can help me?
p.s i try to put the semicolon at the end but same error again..
the insert command is here :


oleDbDataAdapter1.InsertCommand.CommandText =
               "insert into magazina(sasia) values ('" + sasia_totale + "') where emri = '" + listBox1.SelectedItem + "'";
            oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();

解决方案

Too many double quotes!
Change:

oleDbDataAdapter1.InsertCommand.CommandText =
               "insert into magazina(sasia) values ('" + sasia_totale + "') where emri = '" + listBox1.SelectedItem + '"";

To:

oleDbDataAdapter1.InsertCommand.CommandText =
               "insert into magazina(sasia) values ('" + sasia_totale + "') where emri = '" + listBox1.SelectedItem + "'";


You cannot use a WHERE clause with an INSERT statement.

I think you need to change this query to an UPDATE statement.

Also, you should probably Google for "SQL Injection Attack" to find out why using string concatentation to build your SQL statement is a horrible idea and what you can do to fix it. Another Google search would be "C# SQL parameterized query".


Try below one :

oleDbDataAdapter1.InsertCommand.CommandText =
               "insert into magazina(sasia) values ('" + sasia_totale + "')
                where emri = '" + listBox1.SelectedItem + "'";



I hope this will help to you.


这篇关于缺少分号(;)C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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