这个QUERY给出错误有什么不对,请尽快帮助,谢谢。错误附近) [英] This QUERY is giving error what's wrong, please help asap, thanks in advance. error near )
本文介绍了这个QUERY给出错误有什么不对,请尽快帮助,谢谢。错误附近)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string str1="insert into Employee values("+txtempid.Text+",'"+txtEmpName.Text+"',"+txtsal.Text+",'"+txtdob.Text+"','"+txtdoj.Text+"',"+txtorderid.Text+ ")";
推荐答案
通过连接文本框来构建字符串是一个坏主意,原因有两个......
首先,你让自己容易受到SQL注入攻击 - 请参阅 http://bobby-tables.com/ [ ^ ]
因此请使用参数化查询来避免这种情况。
其次,如果你使用参数化查询,你将获得一些其他优点 - 更简单的查询字符串 - 这使得更容易发现任何错误。例如,您不必担心字符串参数周围的单引号。您的命令字符串将变为
Building a string by concatenating text boxes is a bad idea for a couple of reasons ...
Firstly, you are leaving yourself vulnerable to SQL Injection attacks - see http://bobby-tables.com/[^]
So use parameterised queries to avoid this.
Secondly, if you do use parameterised queries, you will gain certain other advantages - simpler query strings - which make it easier to spot any errors. For example you won't have to worry about the single quotes around string parameters. Your command string would become
string str1="insert into Employee values (@empid,@EmpName,@sal,@dob,@doj,@orderid)"
现在查看查询,我可以看出你的问题是由一个(或多个)文本框的内容造成的。
从文本框创建参数时,请在int,string等上使用TryParse方法,以确保文本框的内容确实包含您期望的数据类型。
最后,在调试器中获取str1的最终内容并将其粘贴到查询分析器或类似内容中......您可能会在上下文中获得更详细的错误报告。
http://csharp-station.com/Tutorial/AdoDotNet/Lesson06 [ ^ ]
Hello man,缺少列和char'。
看到这个例子:
Hello man, is missing a columns and char '.
see this example:
INSERT INTO Employee (< columns1 >,< columns2 >, < column3 >) VALUES (< 'valueColumn1' >, < 'valueColumn2' >, < 'valueColumn3' >)
试试这个。
再见
try this.
bye
我认为错误是数据类型不匹配..
所以,更改您的查询:
I think the error is datatype mismatch..
So, change your query :
string str1="insert into Employee values("+txtempid.Text+",'"+txtEmpName.Text+"',"+txtsal.Text+",'"+txtdob.Text+"','"+txtdoj.Text+"',"+txtorderid.Text+ ")";
到
To
string str1="insert into Employee values("+txtempid.Text+",'"+txtEmpName.Text+"',"+txtsal.Text+",#"+txtdob.Text+"#,#"+txtdoj.Text+"#,"+txtorderid.Text+ ")";
#sign代表日期值。
我希望它会对你有所帮助....
Happy Coding ..: - )
# sign represent the date value .
I hope it will help you....
Happy Coding .. :-)
这篇关于这个QUERY给出错误有什么不对,请尽快帮助,谢谢。错误附近)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文