C# 命令未正确结束
这句话有什么问题?我收到错误“命令未正确结束”:C# 命令未正确结束,c#,sql,oracle,C#,Sql,Oracle,这句话有什么问题?我收到错误“命令未正确结束”: 在结尾和“where”之前缺少一个引号: 这个 应该读 + "' where subject_code = '" ^ quote and space here 但请使用参数。不要以这种方式构建SQL,它将导致成功的攻击。您在TextBoxSubjectAbrevisionUpdate.Text值之后缺少一个结束单引号,然后在该引号和之间缺少一个空格,其中: update subjectinfo set subject_name = '"
在结尾和“where”之前缺少一个引号: 这个 应该读
+ "' where subject_code = '"
^ quote and space here
但请使用参数。不要以这种方式构建SQL,它将导致成功的攻击。您在TextBoxSubjectAbrevisionUpdate.Text值之后缺少一个结束单引号,然后在该引号和
之间缺少一个空格,其中
:
update subjectinfo set subject_name = '"
+ textBoxSubjectNameUpdate.Text
+ "' , subject_abbreviation = '"
+ textBoxSubjectAbbreviationUpdate.Text
+ "' where subject_code = '"
+ textBoxSubjectCodeUpdate.Text + "'"
您还邀请SQL注入;请考虑使用,而不是直接将用户输入放在语句中。 < P>理想的是,不应该在代码中使用SQL语句来避免SQL注入。p> 可以使用更干净、性能负担更小的StringBuilder类编写上述特定情况
StringBuilder sb = new StringBuilder("update subjectinfo set subject_name = '");
sb.Append(textBoxSubjectNameUpdate.Text);
sb.Append("' , subject_abbreviation = '");
sb.Append(textBoxSubjectAbbreviationUpdate.Text);
sb.Append("' where subject_code = '");
sb.Append(textBoxSubjectCodeUpdate.Text);
sb.Append("'");
var script sb.ToString()
您只是缺少了
where
前面的一个空格,以及前面文本值的一个结束单引号。您还邀请SQL注入;请考虑使用绑定变量,而不是将用户输入直接放入语句中。除了它容易受到SQL注入的影响之外,首先,使用参数化查询。其次,如果您坚持不这样做,至少使用参数化的stringsthanks。。。我会做出改变的。是的,我现在注意到了,我不确定他是否想把“where”作为插入的一部分。我现在已经改正了。谢谢你在结尾还留了一句话,该死!多任务处理!:)
+ "' where subject_code = '"
^ quote and space here
update subjectinfo set subject_name = '"
+ textBoxSubjectNameUpdate.Text
+ "' , subject_abbreviation = '"
+ textBoxSubjectAbbreviationUpdate.Text
+ "' where subject_code = '"
+ textBoxSubjectCodeUpdate.Text + "'"
StringBuilder sb = new StringBuilder("update subjectinfo set subject_name = '");
sb.Append(textBoxSubjectNameUpdate.Text);
sb.Append("' , subject_abbreviation = '");
sb.Append(textBoxSubjectAbbreviationUpdate.Text);
sb.Append("' where subject_code = '");
sb.Append(textBoxSubjectCodeUpdate.Text);
sb.Append("'");
var script sb.ToString()