插入新記錄時,我不斷收到此錯誤。我忘記了在訪問數據庫中輸入父域,所以我爲這個域插入新行。然後當我運行我的項目時,我收到錯誤。這裏的INSERT命令:插入錯誤:語法錯誤和未知字段
Private Sub Add1_Click(sender As Object, e As EventArgs) Handles Add1.Click
Try
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn.Open()
Dim command As New OleDbCommand("insert into employee ([EmployID], Last_Name, First_Name, MI, Bday, Age, Nationality, [Contact_Number], Sex, Address, Department, Position, TIN, SSS, Pagibig, PhilHealth, Termi_Resi, [Date_hired], Rate_Month, [Date_End], Status, Father_Name, Mother_Name, Civil, Spouse, [Number_of_Children], Child1, Child2, Child3, Child4, Child5, Child6, Child7, Child8, Child9) values (@numberemp, @lname, @fnamemi, @bday, @age, @natio, @contact, @gender, @address, @department, @position, @tin, @sss, @pagibig, @phh, @termiresi, @datehired, @rm, @dateTermiResi, @status, @father, @mother, @civil, @spouse, @numberchild, @child1, @child2, @child3, @child4, @child5, @child6, @child7, @child8, @child9)", conn)
With command.Parameters
.AddWithValue("@numberemp", numberemp.Text)
.AddWithValue("@lname", lname.Text)
.AddWithValue("@fname", fname.Text)
.AddWithValue("@mi", mi.Text)
.AddWithValue("@bday", bday.Text)
.AddWithValue("@age", age.Text)
.AddWithValue("@natio", natio.Text)
.AddWithValue("@contact", contact.Text)
.AddWithValue("@gender", gender.Text)
.AddWithValue("@address", address.Text)
.AddWithValue("@department", department.Text)
.AddWithValue("@position", position.Text)
.AddWithValue("@tim", tin.Text)
.AddWithValue("@sss", sss.Text)
.AddWithValue("@pagibig", pagibig.Text)
.AddWithValue("@phh", phh.Text)
.AddWithValue("@termiresi", termiresi.Text)
.AddWithValue("@datehired", datehired.Text)
.AddWithValue("@rm", rm.Text)
.AddWithValue("@dateTermiResi", dateTermiResi.Text)
.AddWithValue("@status", status.Text)
.AddWithValue("@father", father.Text)
.AddWithValue("@mother", mother.Text)
.AddWithValue("@civil", civil.Text)
.AddWithValue("@spouse", spouse.Text)
.AddWithValue("@numberchild", numberchild.Text)
.AddWithValue("@child1", child1.Text)
.AddWithValue("@child2", child2.Text)
.AddWithValue("@child3", child3.Text)
.AddWithValue("@child4", child4.Text)
.AddWithValue("@child5", child5.Text)
.AddWithValue("@child6", child6.Text)
.AddWithValue("@child7", child7.Text)
.AddWithValue("@child8", child8.Text)
.AddWithValue("@child9", child9.Text)
End With
command.ExecuteNonQuery()
MessageBox.Show("Employee's Informations Successfuly Recorded!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
command.Dispose()
conn.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
我的錯誤是:
INSERT into statement contains the following unknown field name: 'father'. Make sure you have typed the name correctly, and try the operation again.
當我固定的,現在我不斷收到此錯誤:
Syntax error in INSERT INTO statement
我錯過了什麼嗎?
請將錯誤文本添加到您的問題。 – blackpen
這不是VBA。請修復標籤。不要把它們放在標題中。 – Codo
對不起......我現在編輯我的帖子。我包括我的錯誤,並修復了標記:) – wwwMarvsdotcom