Re: Insert to Access DB with Autonumber field

From: Val Mazur (group51a_at_hotmail.com)
Date: 06/25/04


Date: Thu, 24 Jun 2004 21:47:06 -0400

Hi,

First of all why do you open the whole table to insert records? It is very
expensive and in a case of big table you will experience performance issues.
If you need to add something to the database, then use INSERT SQL statement
and it will work muck faster.
Another question is why are you trying to use COM-based ADO with C#. If you
move to C#, then use ADO.NET managed class. Otherwise you might face some
limitations with using ADO through COM Interop
Hard to say why you get this error. It depends what is your actual code. As
I understand this is not a full code.

-- 
Val Mazur
Microsoft MVP
"Microsoft" <graham@integra.uk.net> wrote in message 
news:OCYWVNgWEHA.3984@TK2MSFTNGP09.phx.gbl...
> Hi, i hope someone can help. The following code works in VB:
> Dim sql As String
> Dim oconn As New ADODB.Connection
> Dim ors As New ADODB.Recordset
> oconn.ConnectionString = "...."
> oconn.Open
> sql = "SELECT * FROM Table"
> ors.CursorLocation = adUseClient
> ors.LockType = adLockBatchOptimistic
> ors.Open sql, oconn
> ors.AddNew
> ors(1) = ...
> oRS(2) = ...
> ors.UpdateBatch
> Dim newid As Integer
> newid = ors(0)
>
> When I do exactly the same in c# the UpdateBatch fails, saying that it 
> would
> create a duplicate key. Any ideas?
> Regds
> Graham
>
> 


Relevant Pages

  • Re: Which identity?
    ... > Some postings I read suggested using MAXto retrieve the inserted record ... > each of these 3 SQL features? ... Another way to do it if using the .AddNew method on a Jet based ADO ... Dim rsTest As ADODB.Recordset ...
    (microsoft.public.access.queries)
  • Re: display data to user question
    ... I created a project that has an embedded SQl table with the scenario you ... Dim cn As New SqlConnection("Data ... Protected Sub Page_Load(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: display data to user question
    ... I created a project that has an embedded SQl table with the scenario you ... Dim cn As New SqlConnection("Data ... Protected Sub Page_Load(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: display data to user question
    ... I created a project that has an embedded SQl table with the scenario you ... Dim cn As New SqlConnection("Data ... Protected Sub Page_Load(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Performance von SQL-Abfragen auf Exceltabellen
    ... Nun habe ich es mit SQL auf Exceldaten versucht und konnte das ganze ... Performance konstant bei rund 3 Sekunden. ... Dim iColumnCount As Long ... Dim FirstColumnforSQLexists_jn As String 'j if first column for SQL ...
    (microsoft.public.de.excel)