I'm building a voting system for calls, and have tried to build it in VB. So far this is what I have:
Dim con As New OleDb.OleDbConnection Dim dbProvider As String Dim dbSource As String dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" dbSource = "Data Source = C:\PhonePoll.mdb" con.ConnectionString = dbProvider & dbSource con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\PhonePoll.mdb" con.Open() 'sql = "SELECT * FROM voting" 'da = New OleDb.OleDbDataAdapter(sql, con) 'da.Fill(ds, "voting") If inc <> -1 Then Dim cb As New OleDb.OleDbCommandBuilder(da) Dim dsNewRow As DataRow dsNewRow = ds.Tables("voting").NewRow() dsNewRow.Item("voted") = RadioButton1.Checked.ToString dsNewRow.Item("voted") = RadioButton2.Checked.ToString dsNewRow.Item("voted") = RadioButton3.Checked.ToString dsNewRow.Item("voted") = RadioButton4.Checked.ToString ds.Tables("voting").Rows.Add(dsNewRow) da.Update(ds, "voting") MsgBox("New Record added to the Database") End If MsgBox("Phone call has been logged") con.Close() This code is contained within a "Record Call" button. On the form, there are four radio buttons, all with different text values which should be entered in to the "voting" table.
My problem is that when I select a radio button and click on "Record Button" it then displays this error:
NullReferenceException: Object reference not set to an instance of an object.
This error is displayed on the line
dsNewRow = ds.Tables("voting").NewRow() I'm not sure what I've done wrong.
Cheers for the help!