我认为C#程序错误和Sql [英] C# Program Error And Sql I Think

查看:75
本文介绍了我认为C#程序错误和Sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜。当我想添加新信息时出现此错误:



http://imagizer.imageshack.us/a/img633/1524/vLYY5c.png [ ^ ]



我想删除文件时出现此错误我已经保存了(这个程序就像文件管理器,我可以添加名称 - 大小 - 质量......我们可以在gridview中看到这些信息,当你选择一个文件并双击它时它会打开另一个你可以保存图片或电影的窗口和...这些文件。现在,当我想删除这些图片或电影时,我收到此错误)



http://imagizer.imageshack.us/a/img907/9632/sobClQ.png [ ^ ]



所以,为什么我会收到此错误以及如何修复它?



谢谢你。

hi. i get this error when i want to add a new information :

http://imagizer.imageshack.us/a/img633/1524/vLYY5c.png[^]

and i get this error when i want to delete the file that i have saved ( this program is something like file manager and i can add name - size - quality and .... and we can see these informations in gridview and when u select a file and double click on it it will open u another windows that u can save pic or movie and ... for these file. now when i want to delete these pics or movies i get this error )

http://imagizer.imageshack.us/a/img907/9632/sobClQ.png[^]

so, why i get this error and how to fix it ?

thank u.

推荐答案

查看错误消息 - 它们非常明确。

第一个显而易见:

Look at the error messages - they are pretty explicit.
The first one is obvious:
"Table 'Filelib' does not have the identity property"

所以看看你的UPDATE命令,如果你有一个名为Identity的列,那么用方括号括起来:[Identity]

其次,请注意,没有WHERE子句的UPDATE查询将影响整个表中的每一行...



秒秒更难:

So look at your UPDATE command and if you have a column called "Identity" then surround it with square brackets: "[Identity]"
Second, do note that an UPDATE query with no WHERE clause will affect every single row in the whole table...

The seconds one is harder:

"Incorrect syntax near '='"



几乎可以肯定,你需要使用参数化查询而不是字符串连接:永远不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。



将来不要发布垃圾截图 - 请在此处复制并粘贴代码和错误消息。您的错误的屏幕截图是懒惰和无益的,因为他们切断了一半必要的信息!


Almost certainly it means you need to use a parameterised query instead of string concatenation: never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

And in future, don't post rubbish screenshots - copy and paste the code and error message here instead. Screenshots of your errors are lazy and unhelpful because they cut off half the necessary information!


这篇关于我认为C#程序错误和Sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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