Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New OleDbConnection("provider= microsoft.jet.oledb.4.0;data source=" & CurDir() & "\bilingual1.mdb")
Dim reader As OleDbDataReader
Dim cmd As New OleDbCommand
Try
con.Open()
Dim str As String
str = " insert to yoruba (ọro,itumo,geesi) values ('" & TextBox1.Text & "', '" & RichTextBox1.Text & "', '" & RichTextBox2.Text & "')"
cmd = New OleDbCommand(str, con)
reader = cmd.ExecuteReader
MsgBox("new word added.")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
con.Dispose()
End Try
答案 0 :(得分:0)
INSERT命令不需要Reader。我将Cmd方法更改为ExecuteNonQuery()以获取INSERT命令,并重新格式化命令文本以便于阅读。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New OleDbConnection("provider= microsoft.jet.oledb.4.0;data source=" & CurDir() & "\bilingual1.mdb")
Dim cmd As OleDbCommand
Try
con.Open()
Dim str As String
str = "INSERT INTO [yoruba] (ọro,itumo,geesi) VALUES ('" & TextBox1.Text & "', '" & RichTextBox1.Text & "', '" & RichTextBox2.Text & "');"
cmd = New OleDbCommand(str, con)
cmd.ExecuteNonQuery()
con.Close()
MsgBox("new word added.")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
con.Dispose()
End Try