H
Hexman
Hello all,
I'm facing some issues with the update/insert process.
I have a datatable (dt), use oledbcommandbuilder, datarow (dr),
OledbAccess connection (cn), dataAdapter (adapter). here's the logic
I plan on using. (Ah, if it would only work!!!)
------------------------------------------------------------------------------------
Open a table in Access.
read a transaction from flat file until eof
Build a query ("Select * from purord where ponum = 'flat file
ponumber' ")
Build an Insert Query("insert into Access table ......")
adapter.fill(dt)
if dt.Rows.Count = 0 ' test if record found
Dim dr As DataRow = dt.NewRow
'update dr with key fields only
dr("PODate") = CDate(trnDate)
dt.Rows.Add(dr)
end if
Try
adapter.Update(dt)
Catch ex As Exception
'An exception occurred
MsgBox(ex.tostring())
End Try
'----- Update with non-Key fields -------
dt.Rows(0).Item("POTrnAmt") = CDbl(trnAmt)
Try
adapter.Update(dt)
Catch ex As Exception
'An exception occurred
MsgBox(ex.tostring())
End Try
Go read another transaction above.
-----------------------------------------------------------------------------------------------
Now the problem I have is that if no record is found, the non-Key
fields are never updated. It does create a new row in the datatable
containing the key fields only. It doesn't catch any errors on the
adapter.Update(). It performs the "dt.Rows(0).Item("POTrnAmt") =
CDbl(trnAmt)" statements without errors and It doen't catch any errors
on the second adapter.Update() command, but the non-Key fields don't
update.
My guess is that the update to non-key fields is not triggering a
change to rowstate or I'm missing a refresh command to rowstate or
just missing a command or two.
Can anyone help me out?
Hexman
P.S. If I process a transaction for a records that IS on file, the
update of non-Key fields works fine. Its only when a new record is to
be added that the non-Key updates don't take.
Access 2003, VB.net 2005,
I'm facing some issues with the update/insert process.
I have a datatable (dt), use oledbcommandbuilder, datarow (dr),
OledbAccess connection (cn), dataAdapter (adapter). here's the logic
I plan on using. (Ah, if it would only work!!!)
------------------------------------------------------------------------------------
Open a table in Access.
read a transaction from flat file until eof
Build a query ("Select * from purord where ponum = 'flat file
ponumber' ")
Build an Insert Query("insert into Access table ......")
adapter.fill(dt)
if dt.Rows.Count = 0 ' test if record found
Dim dr As DataRow = dt.NewRow
'update dr with key fields only
dr("PODate") = CDate(trnDate)
dt.Rows.Add(dr)
end if
Try
adapter.Update(dt)
Catch ex As Exception
'An exception occurred
MsgBox(ex.tostring())
End Try
'----- Update with non-Key fields -------
dt.Rows(0).Item("POTrnAmt") = CDbl(trnAmt)
Try
adapter.Update(dt)
Catch ex As Exception
'An exception occurred
MsgBox(ex.tostring())
End Try
Go read another transaction above.
-----------------------------------------------------------------------------------------------
Now the problem I have is that if no record is found, the non-Key
fields are never updated. It does create a new row in the datatable
containing the key fields only. It doesn't catch any errors on the
adapter.Update(). It performs the "dt.Rows(0).Item("POTrnAmt") =
CDbl(trnAmt)" statements without errors and It doen't catch any errors
on the second adapter.Update() command, but the non-Key fields don't
update.
My guess is that the update to non-key fields is not triggering a
change to rowstate or I'm missing a refresh command to rowstate or
just missing a command or two.
Can anyone help me out?
Hexman
P.S. If I process a transaction for a records that IS on file, the
update of non-Key fields works fine. Its only when a new record is to
be added that the non-Key updates don't take.
Access 2003, VB.net 2005,