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
Asked
Active
Viewed 41 times
-1
-
http://www.tutorialspoint.com/sql/ – Ňɏssa Pøngjǣrdenlarp Jun 11 '15 at 02:46
-
Was this question resolved for you? If so, could you post your solution? – tbm0115 Jul 14 '15 at 23:42
1 Answers
0
You shouldn't need a Reader for an INSERT command. I changed the Cmd method to ExecuteNonQuery() for INSERT command and reformatted the command text for readability.
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

tbm0115
- 410
- 11
- 21