.net – 没有定义sqlconnection

我正在尝试更新一些代码.我有一个以此开头的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不知道要使用哪种类型.

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...