's' 附近的语法不正确.字符串 ')' 后的非封闭引号 [英] Incorrect syntax near 's'. Unclosed quotation marks after the character string ')'

查看:16
本文介绍了's' 附近的语法不正确.字符串 ')' 后的非封闭引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 asp.net 和内置数据库创建一个网站,现在我正在尝试解决这个错误 2 个小时.我在查询中使用字符串连接.原始查询:插入帐户持有人值('Yash','Gadhvi','MJShinichi','谁是你最喜欢的演员/女演员?','Yui Aragaki');

I'm creating a website using asp.net and inbuilt database and I'm trying to solve this error for 2 hours now. I'm using string concatenation in my query. Raw query : insert into Account holder values('Yash','Gadhvi','MJShinichi','Who is your favorite actor/Actress?','Yui Aragaki');

      String MyCommand = "insert into AccountHolder values('  "+FNameBox.Text+"  ','  "+LNameBox.Text+"  ','  "+UName.Text+"  ','  "+PassMe.Text+"  ','  "+Qs.Text+"  ','  "+As.Text+"  ')";
    SqlCommand adder = new SqlCommand(MyCommand,sqlcon);
    sqlcon.Open();
    int exe = adder.ExecuteNonQuery();
    sqlcon.Close();

不能使用参数化查询,因为没有过程,除此之外我已经尝试了所有的东西(' 和 " 之间的空格是用来分隔单引号和双引号).我在互联网上搜索过,但它没有太大帮助......它给我的最好的是编译错误.

Can't use parameterized query because there is no procedure, other than that I've tried literally everything (blank spaces between ' and " are to separate single and double quotations). I've searched around on the internet but it didn't help much.... The best what it gave me was compilation error.

推荐答案

为此替换您的代码:

String MyCommand = "insert into AccountHolder values(@FNameBox, @LNameBox, @UName, @PassMe, @Qs, @As)";
SqlCommand adder = new SqlCommand(MyCommand, sqlcon);
adder.Parameters.AddWithValue("@FNameBox", FNameBox.Text);
adder.Parameters.AddWithValue("@LNameBox", LNameBox.Text);
adder.Parameters.AddWithValue("@UName", UName.Text);
adder.Parameters.AddWithValue("@PassMe", PassMe.Text);
adder.Parameters.AddWithValue("@Qs", Qs.Text);
adder.Parameters.AddWithValue("@As", As.Text);   
sqlcon.Open();
int exe = adder.ExecuteNonQuery();
sqlcon.Close();

如果您坚持不带参数继续插入,请检查您的数据,您可能在数据中有一个 '.

If you insist continue the insert without parameters, check your data you probably have a ' inside the data.

这篇关于's' 附近的语法不正确.字符串 ')' 后的非封闭引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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