0 Replies - 438 Views - Last Post: 14 August 2012 - 03:19 AM Rate Topic: -----

#1 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 161
  • Joined: 04-November 10

datatable issues

Posted 14 August 2012 - 03:19 AM

I am have a datatable(myTable) with some information from my database. Now I want to create an exact copy of that datatable(myAuditTable) with the exception of that the copy has an autonumber primary key field, this is so that I can save it into the database. Now when I attempt to save the copy(myAuditTable) into the database I get the error "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." .

Now when I debug and look into the Dataset Visualiser I see that the column which is supposed to be autonumber and primary key has nothing in it.



 myAuditTable = myTable.Copy
            Dim ProductRawMaterial As DataColumn = New DataColumn
            ProductRawMaterial.DataType = System.Type.GetType("System.Int64")
            ProductRawMaterial.AllowDBNull = False
            ProductRawMaterial.Caption = "ProductRawMaterial"
            ProductRawMaterial.ColumnName = "ProductRawMaterial"
            ProductRawMaterial.AutoIncrement = True
            ProductRawMaterial.AutoIncrementSeed = GetmyProductRawMaterialNumber()
            ProductRawMaterial.AutoIncrementStep = 1
            myAuditTable.Columns.Add(ProductRawMaterial)
            Dim myKonn As OleDbConnection = frmLogIn.Connn
            Dim oledbCmdBuilderAudit As OleDbCommandBuilder
            Dim sqlAudit As String = "select * from ProductRawMaterial WHERE ProductCode=@ProductCode"
            Dim oledbAdapterAudit As OleDbDataAdapter = New OleDbDataAdapter(sqlAudit, myKonn)
            oledbAdapterAudit.SelectCommand.Parameters.AddWithValue("@ProductCode", txtProductCode.Text)
            oledbCmdBuilderAudit = New OleDbCommandBuilder(oledbAdapterAudit)
            changes = myTable.GetChanges()
            oledbCmdBuilderAudit.ConflictOption = ConflictOption.OverwriteChanges
            If changes IsNot Nothing Then
                oledbAdapterAudit.AcceptChangesDuringUpdate = False
                oledbAdapterAudit.Fill(myAuditTable)
                'oledbAdapterAudit.Update(myAuditTable)
            End If
            myConn.Close()


Attached image(s)

  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Page 1 of 1