插入新记录时,我一直收到此错误消息。我忘了在访问数据库中输入父字段,因此我为此字段插入新行。然后当我运行我的项目时,我收到错误。这是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语句包含以下未知字段名称:' father'。确保您已正确输入名称,然后再次尝试操作。
当我解决这个问题时,现在我一直收到这个错误:
INSERT INTO语句中的语法错误
我错过了什么吗?
答案 0 :(得分:2)
这应该纠正它。我将@fnamemi
拆分为@fname, @mi
。
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, @fname, @mi, @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)
您有First_Name
和MI
个字段,但只有一个参数代表@fnamemi
。您收到错误,因为您还有一个字段,然后您有值。
[EmployID] @numberemp Last_Name @lname First_Name @fnamemi MI Bday @bday Age @age Nationality @natio [Contact_Number] @contact Sex @gender Address @address Department @department Position @position TIN @tin SSS @sss Pagibig @pagibig PhilHealth @phh Termi_Resi @termiresi [Date_hired] @datehired Rate_Month @rm [Date_End] @dateTermiResi Status @status Father_Name @father Mother_Name @mother Civil @civil Spouse @spouse [Number_of_Children] @numberchild Child1 @child1 Child2 @child2 Child3 @child3 Child4 @child4 Child5 @child5 Child6 @child6 Child7 @child7 Child8 @child8 Child9 @child9