I'm selecting data from SQL Server and attempting to insert it into an Excel workbook, by using ImportRow to copy data between two datatables (
Both datatables are created ... and I'm able to append data from one datatable to the other. However, the changes don't appear in the Excel workbook.
The first dtApRemote.Rows.Count returns 0, and the second returns 150. So records are being added, it appears.
I'm sure this is something small in the syntax, just can't find the right answer yet.
Thanks in advance, as always.
Bryant Farley
"The Dude Abides
Both datatables are created ... and I'm able to append data from one datatable to the other. However, the changes don't appear in the Excel workbook.
Code:
Using sqlConn As New SqlConnection(strConnSql)
' Connect to SQL database
sqlConn.Open()
Dim cmd As New SqlCommand()
cmd.Connection = sqlConn
' Query AP
Dim strSqlAp As String = "SELECT * FROM SomeTable"
'Create the DataAdapter.
Dim da As SqlDataAdapter = New SqlDataAdapter(strSqlAp, sqlConn)
'Fill the DataSet with data.
da.Fill(ds, "AP")
dtAp = ds.Tables("AP")
intApRows = dtAp.Rows.Count
Dim strOledbConnAp As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFileNameApProc & ";" & _
"Extended Properties=""Excel 8.0;HDR=YES"""
Dim conn1 As New System.Data.OleDb.OleDbConnection(strOledbConnAp)
conn1.Open()
Dim da2 As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM [AP$]", conn1)
da2.Fill(ds2, "AP")
dtApRemote = ds2.Tables("AP")
MsgBox(dtApRemote.Rows.Count)
For i As Integer = 0 To intApRows - 1
dtApRemote.ImportRow(dtAp.Rows(i))
Next
da2.Update(dtApRemote)
MsgBox(dtApRemote.Rows.Count)
conn1.Close()
End Using
The first dtApRemote.Rows.Count returns 0, and the second returns 150. So records are being added, it appears.
I'm sure this is something small in the syntax, just can't find the right answer yet.
Thanks in advance, as always.
Bryant Farley
"The Dude Abides