Read from database and fill DataTable

后端 未结 2 1384
醉话见心
醉话见心 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 01:58

    Connection object is for illustration only. The DataAdapter is the key bit:

    Dim strSql As String = "SELECT EmpCode,EmpID,EmpName FROM dbo.Employee"
    Dim dtb As New DataTable
    Using cnn As New SqlConnection(connectionString)
      cnn.Open()
      Using dad As New SqlDataAdapter(strSql, cnn)
        dad.Fill(dtb)
      End Using
      cnn.Close()
    End Using
    

提交回复
热议问题