2016-09-19 31 views
1

新しいレコードを挿入するときにこのエラーが発生します。私はこのフィールドの新しい行を挿入するので、アクセスデータベースに父のフィールドを入力することを忘れました。私のプロジェクトを実行すると、エラーが発生します。 enter image description hereエラーに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コマンドです

Syntax error in INSERT INTO statement

:私は今、私はこのエラーを得続ける、という固定

INSERT into statement contains the following unknown field name: 'father'. Make sure you have typed the name correctly, and try the operation again.

何か不足していますか?

+0

質問にエラーテキストを追加してください。 – blackpen

+0

これはVBAではありません。タグを修正してください。そしてタイトルに入れないでください。 – Codo

+0

申し訳ありません...私は今投稿を編集します。私は私のエラーを含み、タグを固定しました:) – wwwMarvsdotcom

答えて

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_NameMIフィールドが、両方@fnamemiを表現するパラメータを1つだけ持っています。もう1つフィールドがあり、値があるため、エラーが発生しています。

 

[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 
+0

ああ、ありがとうございました。しかし、私はまだ 'INSERT INTO文中の構文エラー'というエラーがあります。私はデータベース内の私のフィールドを標準化する必要がありますか? – wwwMarvsdotcom

関連する問題