1

我正在尝试使用 vb.net 连接到 sql server,但出现此错误:

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

这是鳕鱼源:

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
4

1 回答 1

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
于 2013-01-06T17:29:33.060 回答