使用Visual Studio 2010将新记录添加到数据表中。发生错误 [英] Adding new records to a data table, using Visual Studio 2010. Error occured

查看:119
本文介绍了使用Visual Studio 2010将新记录添加到数据表中。发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误3''System.Data.SqlClient.SqlCommand''不包含''close''的定义,并且没有扩展方法''close''接受类型''System.Data.SqlClient的第一个参数。可以找到SqlCommand''(你错过了使用指令或程序集引用吗?)







我很想明白这意味着什么

Error 3 ''System.Data.SqlClient.SqlCommand'' does not contain a definition for ''close'' and no extension method ''close'' accepting a first argument of type ''System.Data.SqlClient.SqlCommand'' could be found (are you missing a using directive or an assembly reference?)



I am failling to understand what this means

推荐答案

错误信息告诉你究竟是什么问题

The error message is telling you exactly what the problem is
con.Close()



应该是


should be

con.Close();





并使用参数化查询来防止SQL注入攻击。



And use parameterized queries to prevent SQL injection attacks.


要回答你的全新且无关的问题,C#是一种区分大小写的语言。 Close()和close()是不相关的函数调用。 SqlCommand对象没有Close方法,这是错误告诉你的。无论如何,你应该在using语句中包装实现IDisposable的对象。



文档链接 [ ^ ]
To answer your completely new and unrelated question, C# is a case sensitive language. Close() and close() are unrelated function calls. A SqlCommand object does not have a Close method which is what the error is telling you. You should be wrapping objects that implement IDisposable in using statements anyway.

Link to the documentation[^]


这篇关于使用Visual Studio 2010将新记录添加到数据表中。发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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