Hi all,

In my application user is choosing dates (startDate, endDate) and querying
database A (.mdb, via OleDbDataAdapter)
If last record of database A has date lower than endDate than querying
database B for additional records. Than I'm merging two dataset and binding
to datagrid.

BroDataset = BroBond(startDate, endDate)
        Try
            middleDate = CStr(BroDataset.Tables(0).Compute("Max([Deal
_Date])", Nothing))
        Catch exc As System.InvalidCastException
            middleDate = startDate
        End Try

        If CDate(middleDate) < CDate(endDate) Then

            BrokerageDataset = BrokerageBond(middleDate, endDate)
            BroDataset.Merge(BrokerageDataset)
...
Me.BroTrueDBGrid.DataSource = BroDataset
Me.BroTrueDBGrid.DataMember = BroDataset.Tables(0).TableName

Users can make additional corrections by hand and have a button on the form
to update database A.

Dim startDate As String = Me.StartDTPicker.Text
Dim endDate As String = Me.EndDTPicker.Text
Dim result As MsgBoxResult
result = MsgBox("Are you sure...?", MsgBoxStyle.OKCancel)
If result = MsgBoxResult.OK Then
UpdateBro (startDate, endDate)

Public Sub UpdateBonds(ByVal startDate As String, ByVal endDate As String)

Dim PR_STR_CONN As String = sciezka do bazy A
Dim STR_SELECT_SQL As String = "SELECT ID, [Deal Date], Seller, [Bro Sel],
Buyer, [Bro Buy], Amount, TBonds, Nick, Jacek, Daniel FROM Bonds WHERE
([Deal Date] > #" & startDate & "#) AND ([Deal Date] < #" & endDate & "#)
ORDER BY ID"

Dim connOleDb As OleDbConnection
connOleDb = New OleDbConnection(PR_STR_CONN)
Dim updDA As OleDbDataAdapter = New OleDbDataAdapter(STR_SELECT_SQL,
connOleDb)
Dim updDataSet As New DataSet
Dim updCommBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(updDA)
updCommBuilder.QuotePrefix = "["
updCommBuilder.QuoteSuffix = "]"
connOleDb.Open()

Me.BroTrueDBGrid.UpdateData() 'updating dataset with changes done in
datagrid
updDataSet = Me.BroTrueDBGrid.DataSource

If updDataSet.HasChanges Then
    Try
        updDA.Update(updDataSet, updDataSet.Tables(0).TableName)
    Catch e As System.Data.DBConcurrencyException
        MsgBox(e.ToString, MsgBoxStyle.Information)
    Catch exc As System.Data.OleDb.OleDbException
        MsgBox(exc.ToString, MsgBoxStyle.Information)
    End Try
End If
connOleDb.Close()
End Sub

If I've got only data from database A in datagrid, update process works
correct. But if I've got also new records (from database B) I'm receiving
System.Data.DBConcurrencyException (concurrency error). Does anyone know how
to solve this problem?

TIA
Przemek

===================================
This list is hosted by DevelopMentorŽ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to