A datagridview. I have been trying some other things. Here is the newest way that I am doing it. I basically changed the update command of the dataadapter to a insert command.
-
-
Dim row As DataRow = dsHardware.Tables("Computers").NewRow
-
row("Style") = cmbAddStyle.SelectedItem.Key.ToString
-
row("Location") = cmbAddLocation.SelectedItem.key.ToString
-
row("Sys_ID") = txtAddName.Text
-
row("Assignment") = txtAddOwner.Text
-
row("Dell_Tag") = txtAddTag.Text
-
row("Processor") = txtAddProcessor.Text
-
row("RAM") = txtAddRam.Text
-
row("Hard_Drive") = txtAddHardDrive.Text
-
row("Windows_OS") = txtAddos.Text
-
row("Role") = txtAddRole.Text
-
row("Netware") = chkAddNetware.Checked
-
row("RecordNum") = dsHardware.Tables("Computers").Compute("Max(RecordNum)", Nothing) + 1
-
dsHardware.Tables("Computers").Rows.Add(row)
-
MsgBox(row("RecordNum").ToString)
-
MsgBox(dsHardware.Tables("Computers").Rows(dsHardware.Tables("Computers").Rows.Count - 1)("RecordNum").ToString)
-
-
-
'End the editing of the dataset so we can update the database
-
Me.BindingContext(dsHardware, "Computers").EndCurrentEdit()
-
Me.BindingContext(dsHardware, "Style").EndCurrentEdit()
-
Me.BindingContext(dsHardware, "Location").EndCurrentEdit()
-
-
'Create SQL Query
-
Dim query As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(daComputers)
-
query.GetInsertCommand()
-
daComputers.InsertCommand = query.GetInsertCommand
-
-
'And Update the database - If creation of location or style ever occurs wrap the updates in the sql catcher and update the database all at once
-
daComputers.Update(dsHardware, "Computers")
-
This code has the same outcome. "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. " This error occurs on the daComputers.Update(dsHardware, "Computers") line
I think it comes from the dataset or datadapter not knowing that I inserted a row, and it is creating another row with the same primary key.