“System.Data.SqlClient.SqlConnection”类型的值无法转换为“1维数组”

时间:2013-01-06 17:27:04

标签: vb.net ado.net

我正在尝试使用vb.net连接到sql server但是我收到了这个错误:

  

类型'System.Data.SqlClient.SqlConnection'的值无法转换为'System.Data.SqlClient.SqlConnection'的1维数组。

这是鳕鱼来源:

Imports System.Data.SqlClient

Public Class Form1

    Dim connection As SqlConnection()
    Dim reader As SqlDataReader


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            connection = New SqlConnection("data source=.; initial catalog=tp2_ado; integrated security = sspi")
        Catch ex As Exception
            MessageBox.Show(ex.Message())
        End Try

    End Sub
End Class

1 个答案:

答案 0 :(得分:3)

Imports System.Data.SqlClient

Public Class Form1

    Dim connection As SqlConnection ' this should not be an array !
    Dim reader As SqlDataReader


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            connection = New SqlConnection("data source=.; initial catalog=tp2_ado; integrated security = sspi")
        Catch ex As Exception
            MessageBox.Show(ex.Message())
        End Try

    End Sub
End Class