Hi, as part of a computing project I am writing a program to add, edit and delete data from an access database.
I have successfully written code to edit data but when adding a row to the dataset I run into a problem.
This is the code in my button which adds a new record.
These are my global declarations:Code:Dim cb As New OleDb.OleDbCommandBuilder(da) Dim NewRow As DataRow NewRow = ds.Tables("CandidateID").NewRow NewRow.Item(0) = TxtCandidateID.Text NewRow.Item(1) = TxtFirstName.Text NewRow.Item(2) = TxtSecondName.Text NewRow.Item(3) = TxtHospital.Text NewRow.Item(4) = TxtPosistionHeld.Text NewRow.Item(5) = TxtOTPhysio.Text NewRow.Item(6) = TxtNoYearsInHands.Text NewRow.Item(7) = TxtSpeciality.Text NewRow.Item(8) = TxtBAHTNo.Text NewRow.Item(9) = TxtAddressOfHospital.Text NewRow.Item(10) = TxtAddressForCorrespondance.Text NewRow.Item(11) = TxtTelHome.Text NewRow.Item(12) = TxtTelWork.Text NewRow.Item(13) = TxtFax.Text NewRow.Item(14) = TxtEmail.Text NewRow.Item(15) = TxtReceipt.Text NewRow.Item(16) = TxtInvoice.Text NewRow.Item(17) = TxtDietaryNeeds.Text NewRow.Item(18) = TxtPhysicalLearningNeeds.Text ds.Tables("CandidateID").Rows.Add(NewRow) da.Update(ds, "CandidateID") MsgBox("New record added")
When I click the button I ge the error message : Object reference not set to an instance of an object.Code:Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String = "SELECT * FROM TblCandidate"
The line "NewRow = ds.Tables("CandidateID").NewRow" is highlighted.
Can anyone help?
Thanks in advance.
Joe




Reply With Quote