I have been this problem for a week and searching every existing forum for an answer maybe this time that i post my own problem.
My problem was in saving a data in a database. I have a datagrid that was bind to it but appear nothing. I'm using .mdb access database. the mdb table name was tblinformation.
It appears that my problem was in INSERT INTO statement, because there was a msgbox appears that everytime i try to save a data from textbox. and lastly, I'm new to vb.net >..<
btw here's my code:
Imports System.Data.OleDb
Public Class frmbookinfo
Dim cnn As New OleDb.OleDbConnection
Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Try
cnn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=D:\AmosBooks_System\AmosBooks_System\database.mdb")
Dim command As String
command = "INSERT INTO tblinformation(title, author, isbn, category, edition, pages, language, yearofpublication, bcode, price) VALUES (@title, @author, @isbn, @category, @edition, @pages, @language, @yearofpublication, @bcode, @price)"
cnn.Open()
Dim cmd As OleDbCommand
cmd = New OleDbCommand(command, cnn)
cmd.Parameters.AddWithValue("@title", txttitle.Text)
cmd.Parameters.AddWithValue("@author", txtauthor.Text)
cmd.Parameters.AddWithValue("@isbn", txtisbn.Text)
cmd.Parameters.AddWithValue("@category", txtcategory.Text)
cmd.Parameters.AddWithValue("@edition", txtedition.Text)
cmd.Parameters.AddWithValue("@pages", txtpages.Text)
cmd.Parameters.AddWithValue("@language", cmblanguage.Text)
cmd.Parameters.AddWithValue("@yearofpublication", dtyearpub.Text)
cmd.Parameters.AddWithValue("@bcode", txtbcode.Text)
cmd.Parameters.AddWithValue("@price", txtprice.Text)
cmd.ExecuteNonQuery()
Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
cnn.Close()
End Try
End Sub