Insert to Access DB with Autonumber field

From: Microsoft (graham_at_integra.uk.net)
Date: 06/24/04

  • Next message: jpaganelli_at_san.rr.com: "Re: ADO ActiveConnection failed"
    Date: Thu, 24 Jun 2004 16:53:05 +0100
    
    

    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


  • Next message: jpaganelli_at_san.rr.com: "Re: ADO ActiveConnection failed"

    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)