Read from database and fill DataTable

后端 未结 2 1380
醉话见心
醉话见心 2020-12-18 01:44

I\'m getting a set of data by a DataReader and assigning to a string. Now I need to fill the DataTable columns with the query fields. The Dat

2条回答
  •  感动是毒
    2020-12-18 02:17

    Private Function LoaderData(ByVal strSql As String) As DataTable
        Dim cnn As SqlConnection
        Dim dad As SqlDataAdapter
    
        Dim dtb As New DataTable
        cnn = New SqlConnection(My.Settings.mySqlConnectionString)
        Try
            cnn.Open()
            dad = New SqlDataAdapter(strSql, cnn)
            dad.Fill(dtb)
            cnn.Close()
            dad.Dispose()
        Catch ex As Exception
            cnn.Close()
            MsgBox(ex.Message)
        End Try
        Return dtb
    End Function
    

提交回复
热议问题