G
Guest
Hi All!!!
Seasons Greetings....
I have read a lot of the post regarding CommandBuilder, InsertCommand and
Update. The code below works....
'This is a foxpro table that matches my MS SQL Table
fpDA = New OleDbDataAdapter("select * from table", GetConnection)
flat = New System.Data.DataSet()
fpDA.Fill(flat, "table")
Try
Dim cn As New Data.SqlClient.SqlConnection(ConnSqlClient)
cn.Open()
da = New Data.SqlClient.SqlDataAdapter("select * from table", cn)
cb = New Data.SqlClient.SqlCommandBuilder(da)
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"
da.InsertCommand = cb.GetInsertCommand()
Dim p As Data.SqlClient.SqlParameter
Dim row As Data.DataRow
Dim col As Data.DataColumn
For Each row In flat.Tables("table").Rows
For Each p In da.InsertCommand.Parameters
p.Value = row.Item(p.SourceColumn)
Next
affectedRows += da.InsertCommand.ExecuteNonQuery
Next
Return affectedRows
Catch ex As Exception
MsgBox(ex.Source & vbCrLf & ex.Message)
End Try
There should be more documentation for the "Update" command from Microsoft.
It seems that if you just wanted to insert an unmodified table directly into
SQL server using CommandBuilder is a no go. Once again...there should be
documentation showing how to insert unmodified data (rowstate is unchanged)
into an SQL server database with out getting a headache and eye strain.
Markus McGee
Seasons Greetings....
I have read a lot of the post regarding CommandBuilder, InsertCommand and
Update. The code below works....
'This is a foxpro table that matches my MS SQL Table
fpDA = New OleDbDataAdapter("select * from table", GetConnection)
flat = New System.Data.DataSet()
fpDA.Fill(flat, "table")
Try
Dim cn As New Data.SqlClient.SqlConnection(ConnSqlClient)
cn.Open()
da = New Data.SqlClient.SqlDataAdapter("select * from table", cn)
cb = New Data.SqlClient.SqlCommandBuilder(da)
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"
da.InsertCommand = cb.GetInsertCommand()
Dim p As Data.SqlClient.SqlParameter
Dim row As Data.DataRow
Dim col As Data.DataColumn
For Each row In flat.Tables("table").Rows
For Each p In da.InsertCommand.Parameters
p.Value = row.Item(p.SourceColumn)
Next
affectedRows += da.InsertCommand.ExecuteNonQuery
Next
Return affectedRows
Catch ex As Exception
MsgBox(ex.Source & vbCrLf & ex.Message)
End Try
There should be more documentation for the "Update" command from Microsoft.
It seems that if you just wanted to insert an unmodified table directly into
SQL server using CommandBuilder is a no go. Once again...there should be
documentation showing how to insert unmodified data (rowstate is unchanged)
into an SQL server database with out getting a headache and eye strain.
Markus McGee