我是VB 2010的新手。我一直在尝试使用ms访问作为数据库开发一个小型数据库。我不知道为什么我得到这个错误"对象引用未设置为对象的实例。"。我已经尝试了很多网站,但在网站上没有适当的解决方案。我的代码是:
Public Class Form1
Dim con As New OleDbConnection()
Dim ds As New DataSet
Dim inc As Integer
Dim maxRows As Integer
Dim sql_query As String
Dim da As OleDbDataAdapter
Dim cmd As New OleDbCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=C:\BILL\BILL_DATA.MDB"
con.Open()
MsgBox("Opened")
sql_query = "SELECT * FROM tblBill"
da = New OleDb.OleDbDataAdapter(sql_query, con)
da.Fill(ds, "tblBill")
con.Close()
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
End
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If inc <> -1 Then
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
Dim ds As DataSet = New DataSet
Dim dt As DataTable = ds.Tables("tblBill")
Dim newRow As DataRow = dt.NewRow()
newRow.Item("BillNo") = txtBillNo.Text
newRow.Item("BillDate") = dtpApprDate.Text
newRow.Item("Party") = txtParty.Text
dt.Rows.Add(newRow)
da.Update(ds, "tblBill")
End If
End Sub
End Class