VB2008将Listbox里的内容添加到Access新行中,高手请进!
我想将listbox里一个值添加到数据库中新的一行去,以下是程序代码,但程序运行后老是说“未将对象引用设置到对象”,希望这里有懂的人能够帮忙看看这个问题,谢谢了!!Dim OLDA As OleDbDataAdapter = New OleDbDataAdapter
Dim conn As OleDbConnection = New OleDbConnection
Dim cmd As OleDbCommand = New OleDbCommand
Dim DT As DataTable = New DataTable
Dim DataSet1 As DataSet = New DataSet
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\competition\files\food.mdb"
cmd.CommandText = "select * from 食品流通表"
cmd.Connection = conn
OLDA.SelectCommand = cmd
Dim builder As OleDb.OleDbCommandBuilder = New OleDbCommandBuilder(OLDA)
conn.Open()
OLDA.Fill(DataSet1, "食品流通表")
DT = DataSet1.Tables("食品流通表")
conn.Close()
conn = Nothing
Dim myrow As DataRow = DT.NewRow()
myrow("ID") = ListBox1.Items.Item(0)
DT.Rows.Add(myrow)
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\competition\files\food.mdb"
cmd.CommandText = " INSERT into 食品流通表(ID) values ( '" & ListBox1.Items(0) & "' )"
cmd.Connection = conn
OLDA.InsertCommand = cmd
Dim builder1 As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder
conn.Open()
DataSet1 = New DataSet()
OLDA.Fill(DataSet1, "食品流通表")
conn.Close()
conn = Nothing
补充:VB , 数据库(包含打印,安装,报表)