1 Replies - 541 Views - Last Post: 26 August 2013 - 04:46 AM Rate Topic: -----

#1 cbu007zn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 20-August 13

I get an error “index or primary key cannot contain a null value”

Posted 26 August 2013 - 03:54 AM

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSR.Click
        If inc <> -1 And txtID.Text <> "" Then


            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsNewRow As DataRow

            dsNewRow = ds.Tables("IBCARIP").NewRow()


            ds.Tables("IBCARIP").Rows(inc).Item("EmpCode") = txtID.Text
            ds.Tables("IBCARIP").Rows(inc).Item("IDNumber") = txtIDN.Text
            ds.Tables("IBCARIP").Rows(inc).Item("FName") = txtName.Text
            ds.Tables("IBCARIP").Rows(inc).Item("SName") = txtSName.Text
            ds.Tables("IBCARIP").Rows(inc).Item("Jtitle") = txtJD.Text
            ds.Tables("IBCARIP").Rows(inc).Item("Initials") = txtIn.Text
            ds.Tables("IBCARIP").Rows(inc).Item("Gender") = cmbSex.Text
            ds.Tables("IBCARIP").Rows(inc).Item("Title") = cmbTt.Text
            ds.Tables("IBCARIP").Rows(inc).Item("Age") = txtAge.Text
            ds.Tables("IBCARIP").Rows(inc).Item("PAddress") = txtPAd.Text
            ds.Tables("IBCARIP").Rows(inc).Item("POAddress") = txtPOAd.Text
            ds.Tables("IBCARIP").Rows(inc).Item("CNumber") = txtCNos.Text
            ds.Tables("IBCARIP").Rows(inc).Item("Ailments") = txtAil.Text
            ds.Tables("IBCARIP").Rows(inc).Item("NKName") = txtNK.Text
            ds.Tables("IBCARIP").Rows(inc).Item("NKAddress") = txtNKAddress.Text
            ds.Tables("IBCARIP").Rows(inc).Item("NKNumbers") = txtNKNos.Text
            ds.Tables("IBCARIP").Rows(inc).Item("NRate") = txtNR.Text
            ds.Tables("IBCARIP").Rows(inc).Item("OTRate") = txtOTR.Text
            ds.Tables("IBCARIP").Rows(inc).Item("BName") = cmbBnk.Text
            ds.Tables("IBCARIP").Rows(inc).Item("ANumber") = txtAN.Text
            ds.Tables("IBCARIP").Rows(inc).Item("AType") = cmbAT.Text
            ds.Tables("IBCARIP").Rows(inc).Item("BCode") = txtBC.Text
            ds.Tables("IBCARIP").Rows(inc).Item("BBName") = txtBB.Text
            ds.Tables("IBCARIP").Rows(inc).Item("Notes") = txtNotes.Text
            ds.Tables("IBCARIP").Rows(inc).Item("MStatus") = cmbMS.Text
            '  da.Update(ds, "IBCARIP")

            ds.Tables("IBCARIP").Rows.Add(dsNewRow)

            da.Update(ds, "IBCARIP")

            MsgBox("New Record added to the Database")
        Else
            MsgBox("Please ensure all  important fields are entered", MsgBoxStyle.OkOnly)


        End If
    End Sub
End Class

besides this error when i go to the access table i discover that this code replaces the first record in the table, with the new values i put

This post has been edited by andrewsw: 26 August 2013 - 04:44 AM
Reason for edit:: Please use CODE tags


Is This A Good Question/Topic? 0
  • +

Replies To: I get an error “index or primary key cannot contain a null value”

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3523
  • View blog
  • Posts: 12,031
  • Joined: 12-December 12

Re: I get an error “index or primary key cannot contain a null value”

Posted 26 August 2013 - 04:46 AM

What is the name of your primary-key field and what is its data-type?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1