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.
我的问题是在数据库中保存数据。我有一个datagrid被绑定在上面,但什么都没有。我正在使用。mdb访问数据库。mdb表名为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 >..<
我的问题似乎是插入到语句中,因为每次我试图从文本框中保存数据时,都会出现一个msgbox。最后,我是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
1 个解决方案
#1
3
The syntax error is caused by the word LANGUAGE in the field names.
This word is reserved in JET-SQL and thus should be enclosed in square brackets
语法错误是由字段名中的语言引起的。这个词在JET-SQL中保留,因此应该用方括号括起来
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)"
#1
3
The syntax error is caused by the word LANGUAGE in the field names.
This word is reserved in JET-SQL and thus should be enclosed in square brackets
语法错误是由字段名中的语言引起的。这个词在JET-SQL中保留,因此应该用方括号括起来
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)"