我正在爲調用構建一個投票系統,並試圖在VB中構建它。到目前爲止,這是我的:VB應用程序中的NullReferenceException錯誤?
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()
此代碼包含在「記錄呼叫」按鈕。在表格上,有四個單選按鈕,全部都有不同的文本值,應該輸入到「投票」表中。
我的問題是,當我選擇一個單選按鈕,然後單擊「錄音鍵」,它則顯示此錯誤:
NullReferenceException: Object reference not set to an instance of an object.
顯示上線
dsNewRow = ds.Tables("voting").NewRow()
我」這個錯誤我不知道我做錯了什麼。
歡呼聲!
我不明白,我評論他們出來,因爲它沒有擺在首位的工作。我現在取消註釋他們,它的作品?謝謝您的幫助! – mickburkejnr 2011-04-11 22:30:39