filling a dataset with two tables using a single query
From: Jiho Han (jiho.han_at_infinityinfo.com)
Date: 03/23/05
- Next message: Elvis: "Re: AS400 - Ado.Net from Vb.Net Slow Query Times"
- Previous message: Ryan: "How to specify a schema when filling a DataTable from a .csv file"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 23 Mar 2005 09:45:41 -0500
This something easily done in ADO but it's turning out to be unnecessarily
complicated in ADO.NET.
Consider a SQL statement like this:
SELECT A1.OPPORTUNITYID, A1.DESCRIPTION, A1.STATUS, A2.OPPORTUNITYID
EXTOPPID, A2.SOURCE
FROM OPPORTUNITY A1 INNER JOIN OPPEXT A2 ON (A1.OPPORTUNITYID =
A2.OPPORTUNITYID)
WHERE A1.DESCRIPTION = 'abc123'
In ADO, the following code will locate the record and if found, update both
tables with optimistic concurrency.
Set objConn = New ADODB.Connection
' assume connection opened
Set objRS = New ADODB.Recordset
With objRS
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "<above sql here>", objConn
If Not .EOF Then
.Fields("STATUS").Value = "Open"
.Fields("SOURCE").Value = "Import"
.Update
End If
.Close
End With
What's more, not seen in the code is that, the recordset knows how to
generate the insert/update sql statement dynamically -- parameterized and
prepared if necessary -- using only the fields that are modified.
Now in ADO.NET, there doesn't seem to be a simple way to do this. What I've
seen so far, requires two separate Adapter to be created, which will result
in two separate trips to the DB.
If I try to do it in one single trip, using the above query and
TableMappings, I don't know how I would do that other than:
1. Load the resultset as an untyped dataset or use a datareader.
2. Assign each column values to the typed dataset or an untyped dataset
accordingly.
3. Use DataAdapter on the assigned dataset to commit the changes.
The biggest hurdle is that the dynamic sql generation capability of classic
ADO is nowhere to be found. CommandBuilder doesn't handle optimistic
concurrency at all and the Wizard only creates the necessary sql statements
one time -- static.
Am I missing something here or does this seem like a step backward?
Thanks in advance.
Jiho
- Next message: Elvis: "Re: AS400 - Ado.Net from Vb.Net Slow Query Times"
- Previous message: Ryan: "How to specify a schema when filling a DataTable from a .csv file"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|