我在VB中的代码中遇到了几个错误,我无法弄清楚如何解决它。
第一个错误在以下部分中说
value cannot be null parameter name: data table
da.Fill(dt, "ORDER")
Con.Close()
第二次错误在此部分中:
dsNewRow = ds.Tables(0).NewRow()
以下是整个代码:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source=C:\Users\pao\Desktop\Projecto1.accdb"
Con.ConnectionString = dbProvider & dbSource
Con.Open()
sql = "SELECT *FROM ORDER"
da = New OleDb.OleDbDataAdapter(sql, Con)
da.Fill(dt, "ORDER")
Con.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If name_.TextLength > 0 And address_.TextLength > 0 And key.TextLength > 0 Then
Dim pizzaArr() = pizza.ToArray()
Dim spagArr() = spaghetti.ToArray()
Dim grindersArr() = grinders.ToArray()
Dim dsNewRow As DataRow
For Each element As String In grindersArr
MsgBox(element)
Next
dsNewRow = ds.Tables(0).NewRow()
dsNewRow.Item(0) = key.Text
dsNewRow.Item(1) = name_.Text
dsNewRow.Item(2) = address_.Text
ds.Tables("ORDER").Rows.Add(dsNewRow)
da.Update(ds, "ORDER")
MsgBox("ORDER ADDED", MsgBoxStyle.Information, "record")
maxrows = ds.Tables("ORDER").Rows.Count
''
Else
MsgBox("COMPLETE THE FORM!", MsgBoxStyle.Exclamation, "INCOMPLETE!")
Exit Sub
End If
'' Dim cb As New OleDb.OleDbCommandBuilder(da)
'' Dim dsNewRow As DataRow
'' dsNewRow = ds.Tables("form").NewRow()
'' dsNewRow.Item(0) = key.Text
'' dsNewRow.Item(1) = name_.Text
'' dsNewRow.Item(2) = address_.Text
'' ds.Tables("form").Rows.Add(dsNewRow)
MsgBox("RECORD ADDED", MsgBoxStyle.Information, "record")
MaxRows = ds.Tables("form").Rows.Count
End Sub