加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

.net – 没有定义sqlconnection

发布时间:2020-12-17 07:28:12 所属栏目:百科 来源:网络整理
导读:我正在尝试更新一些代码.我有一个以此开头的vb文件… Imports System.Data.SqlClientImports System.Data.SqlImports System.Data.SqlTypesImports System.Configurationscript runat="server" ……而且它在这里失败了…… Using oConn As SqlConnection = N
我正在尝试更新一些代码.我有一个以此开头的vb文件…

Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports System.Configuration

<script runat="server">

……而且它在这里失败了……

Using oConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("tps_write").ConnectionString())

它返回的错误是……

“Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type ‘SqlConnection’ is not defined.”

我错过了一些系统类吗?

编辑:我更新了代码…

Using oConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("tps_write").ConnectionString())

……它接受了它.为什么每次我使用该类中的对象时都需要显式写出System.Data.SqlClient?

解决方法

EDIT: I updated the code to this…

Using oConn As
System.Data.SqlClient.SqlConnection =
New
System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings(“tps_write”).ConnectionString())

…and it accepts it. Why do I need to
explicitly write out
System.Data.SqlClient every time I use
an object from that class???

我最好的猜测是,有一个名为SqlConnection的类,在您明确指定System.Data.SqlClient.SqlConnection之前,.NET不知道要使用哪种类型.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读