|
|
|
date: Thu, 04 May 2006 07:19:01 -0700,
group: microsoft.public.dotnet.datatools
back
Re: Building updatecommand .Net 1.1 + VFPOLEDB + dBase
I've searched the internet more, but I couldn't modify the schema on the
fly, so I've made a small piece of coding in vb to build the necessary
Updatecommand, based on the Insertcommand generating by the
OleDbCommandBuilder. It works, but if anybody has some better or more
direct idea, please, don't keep it in himsel ;-)
If anybody is interested in it, my code is the following (there are some
declarations before, you may find them out):
cnDBase = New OleDbConnection(strConn)
daLoads.SelectCommand = New OleDbCommand(strSelect, cnDBase)
daLoads.TableMappings.Add(New
System.Data.Common.DataTableMapping("Table", strTable))
Dim cb As New OleDbCommandBuilder(daLoads)
Dim strUpdate As String = cb.GetInsertCommand.CommandText
Dim ixComma As Integer = InStr(strUpdate, ", ")
Dim ixKeyField As Integer = InStr(strUpdate, "(") + 1
strUpdate = Replace(Mid(strUpdate, ixComma + 2, InStrRev(strUpdate, ")
VAL") - InStr(strUpdate, ", ") - 3) & " , ", " , ", "=?,")
strUpdate = "UPDATE '" & strTable & "' SET " & strUpdate.TrimEnd(","c) &
" WHERE" & Mid(cb.GetInsertCommand.CommandText, ixKeyField, ixComma -
ixKeyField - 1) & "=?"
Dim cmdUpdateDBase As System.Data.OleDb.OleDbCommand = New
OleDbCommand(strUpdate, cnDBase)
For ixPar As Integer = 1 To cb.GetInsertCommand.Parameters.Count
Dim objUpdate As OleDbParameter =
cb.GetInsertCommand.Parameters(ixPar Mod
cb.GetInsertCommand.Parameters.Count)
cmdUpdateDBase.Parameters.Add(objUpdate.ParameterName.Insert(1,
"@"), objUpdate.OleDbType, objUpdate.Size, objUpdate.SourceColumn)
Next ixPar
daLoads.UpdateCommand = cmdUpdateDBase
cb.Dispose()
daLoads.Fill(dsLoads)
bla-bla...
*** Sent via Developersdex http://www.developersdex.com ***
date: Fri, 05 May 2006 13:17:58 -0700
author: John Littlewood
|
|