Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Store Procedure (Query)
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00757066
Message ID:
00757367
Views:
8
That's correct but for small datasets it shouldn't make too much of an impact on performance. Unfortunately, Access doesn't allow for batch queries and output parameters which offer the best performance.

>Keep in mind that this hits the database twice for every row insert, once to get the ID and once to insert the row. If you are inserting a lot of children records for a parent in which you know the parent ID, it may be better to do the batch insert and then requery the child records based on the parent (foreign) key.
>
>Have Fun,
>-B
>
>>Hi Wilson,
>>
>>Microsoft Access doesn't support batch queries and doesn't support output parameters on stored procedures. To retrieve values after an update occurs you can use events of the DataAdapter object. There are two events exposed that the DataAdapter throws when it submits the changes cached in a DataRow: RowUpdating and RowUpdated. The former occurs just before you submit the change and the latter occurs immediately after you submit the change. If you submit the changes in multiple rows, the RowUpdating and Row­Updated events will fire for each row. You can use the RowUpdated event to fetch the new value that the database generates for the updated row. Here is some sample code that shows how this is done:
>>
>>
>>Imports System
>>Imports System.Data
>>Imports System.Data.OleDb
>>Imports Microsoft.VisualBasic
>>
>>Public class Sample
>>
>>  Shared nwindConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
>>                                              "Data Source=c:\Program Files\Microsoft Office\Office\Samples\northwind.mdb;")
>>
>>  Public Shared Sub Main()
>>
>>    ' Use the DataAdapter to fill and update the DataSet.
>>    Dim catDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT CategoryID, CategoryName FROM Categories ORDER BY CategoryID", nwindConn)
>>
>>    catDA.InsertCommand = New OleDbCommand("INSERT INTO Categories (CategoryName) Values(?)", nwindConn)
>>    catDA.InsertCommand.CommandType = CommandType.Text
>>
>>    catDA.InsertCommand.Parameters.Add("@CategoryName", OleDbType.Char, 15, "CategoryName")
>>
>>    nwindConn.Open()
>>
>>    ' Fill the DataSet.
>>    Dim catDS As DataSet = New DataSet
>>    catDA.Fill(catDS, "Categories")
>>
>>    ' Add a new row.
>>    Dim newRow As DataRow = catDS.Tables("Categories").NewRow()
>>    newRow("CategoryName") = "New Category"
>>    catDS.Tables("Categories").Rows.Add(newRow)
>>
>>    ' Include an event to fill in the Autonumber value.
>>    AddHandler catDA.RowUpdated, New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)
>>
>>    ' Update the DataSet.
>>    catDA.Update(catDS, "Categories")
>>
>>    nwindConn.Close()
>>  End Sub
>>
>>  Private Shared Sub OnRowUpdated(sender As Object, args As OleDbRowUpdatedEventArgs)
>>    ' Include a variable and a command to retrieve the identity value from the Access database.
>>    Dim newID As Integer = 0
>>    Dim idCMD As OleDbCommand = New OleDbCommand("SELECT @@IDENTITY", nwindConn)
>>
>>    If args.StatementType = StatementType.Insert
>>      ' Retrieve the identity value and store it in the CategoryID column.
>>      newID = CInt(idCMD.ExecuteScalar())
>>      args.Row("CategoryID") = newID
>>      args.Row.AcceptChanges()
>>    End If
>>  End Sub
>>End Class
>>
>>
>>>I want to make a query in access that update a table and return the value of a field.
>>>
>>>is this possible?
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform