5 Replies - 3010 Views - Last Post: 06 December 2012 - 04:30 AM Rate Topic: -----

#1 Guitora Kuronato  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 28
  • Joined: 02-December 12

ExecuteNonQuery Error vb2010 ms access

Posted 02 December 2012 - 10:21 AM

Hello
I'm new to VIsual Studio 2010, i just study how to made a program that connect to my database to ms access 2007
but at my save button code,, got error executenonquery
this is my code

Private Sub savebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savebutton.Click
        If MaskedTextBox1.Text = String.Empty Then MsgBox("Please Insert Your Employee Number", vbInformation, "Personal Particulars") : MaskedTextBox1.Focus() : Exit Sub
        If MaskedTextBox2.Text = String.Empty Then MsgBox("Please Insert Your Name", vbInformation, "Personal Particulars") : MaskedTextBox2.Focus() : Exit Sub
        If MaskedTextBox3.Text = String.Empty Then MsgBox("Please Insert Position", vbInformation, "Personal Particulars") : MaskedTextBox3.Focus() : Exit Sub
        If MaskedTextBox4.Text = String.Empty Then MsgBox("Please Insert Application Date", vbInformation, "Personal Particulars") : MaskedTextBox4.Focus() : Exit Sub
        If MaskedTextBox5.Text = String.Empty Then MsgBox("Please Insert Your Reasons", vbInformation, "Personal Particulars") : MaskedTextBox5.Focus() : Exit Sub
        If MaskedTextBox6.Text = String.Empty Then MsgBox("Please Insert Apply Date", vbInformation, "Personal Particulars") : MaskedTextBox6.Focus() : Exit Sub
        If MaskedTextBox7.Text = String.Empty Then MsgBox("Please Pick an Option In Notification Form", vbInformation, "Notification Form") : Exit Sub
        If MaskedTextBox1.Text <> String.Empty And MaskedTextBox2.Text <> String.Empty And MaskedTextBox3.Text <> String.Empty And MaskedTextBox4.Text <> String.Empty And MaskedTextBox5.Text <> String.Empty And MaskedTextBox6.Text <> String.Empty And MaskedTextBox7.Text <> String.Empty Then
            Me.LFtableTableAdapter.Fill(Me.LFDBDataSet.LFtable)
            con = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= F:\Project Interview\we\LFDB.accdb")
            con.Open()
            If Not con.State = ConnectionState.Open Then
                con.Open()
            End If
            Dim cmd As New OleDb.OleDbCommand("INSERT INTO LFtable (Employe_no,employe_name,position,application_date,reasons,date_apply,notif) VALUES (@employe_no,@employe_Name,@Position,@application_date,@reasons,@date_apply,@notif)", con)
            cmd.Parameters.AddWithValue("@employe_no", MaskedTextBox1.Text)
            cmd.Parameters.AddWithValue("@employe_name", MaskedTextBox2.Text)
            cmd.Parameters.AddWithValue("@position", MaskedTextBox3.Text)
            cmd.Parameters.AddWithValue("@application_date", MaskedTextBox4.Text)
            cmd.Parameters.AddWithValue("@reasons", MaskedTextBox5.Text)
            cmd.Parameters.AddWithValue("@date_apply", MaskedTextBox6.Text)
            cmd.Parameters.AddWithValue("@notif", MaskedTextBox7.Text)
            cmd.ExecuteNonQuery()
            con.Close()
            MsgBox("Your Data Had Been Saved", vbInformation + vbOKOnly, "Save")
        End If
    End Sub



Please Help Me

Is This A Good Question/Topic? 0
  • +

Replies To: ExecuteNonQuery Error vb2010 ms access

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: ExecuteNonQuery Error vb2010 ms access

Posted 02 December 2012 - 10:22 AM

Wrap that in a try/catch.. and tell us the full error text.

Side note - moving to vb.net.
Was This Post Helpful? 0
  • +
  • -

#3 Guitora Kuronato  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 28
  • Joined: 02-December 12

Re: ExecuteNonQuery Error vb2010 ms access

Posted 02 December 2012 - 10:12 PM

how to make it?
Was This Post Helpful? 0
  • +
  • -

#4 Guitora Kuronato  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 28
  • Joined: 02-December 12

Re: ExecuteNonQuery Error vb2010 ms access

Posted 02 December 2012 - 10:22 PM

Syntax error in INSERT INTO statement
Was This Post Helpful? 0
  • +
  • -

#5 zeeshanef  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 76
  • Joined: 14-April 12

Re: ExecuteNonQuery Error vb2010 ms access

Posted 03 December 2012 - 08:03 AM

1. you add a parameter @position with p(small), but in your Insert query it is @Positions with P(capital).

2. Employe_no is the field name in your query. If it was defined as, start with Capital (E). then it is ok.

make sure that you respect the case sensitivity.

This post has been edited by zeeshanef: 03 December 2012 - 08:04 AM

Was This Post Helpful? 0
  • +
  • -

#6 Guitora Kuronato  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 28
  • Joined: 02-December 12

Re: ExecuteNonQuery Error vb2010 ms access

Posted 06 December 2012 - 04:30 AM

looks like isnt the capital problem
look this

 Me.LFtableTableAdapter.Fill(Me.LFDBDataSet.LFtable)
            con = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= F:\Project Interview\we\LFDB.accdb")
            com = New OleDb.OleDbCommand("insert into LFtable values(@employe_no,@employe_Name,@Position,@application_date,@reasons,@date_apply,@notif)", con)
            con.Open()
            com.Parameters.AddWithValue("@employe_no", MaskedTextBox1.Text)
            com.Parameters.AddWithValue("@employe_name", MaskedTextBox2.Text)
            com.Parameters.AddWithValue("@position", MaskedTextBox3.Text)
            com.Parameters.AddWithValue("@application_date", MaskedTextBox4.Text)
            com.Parameters.AddWithValue("@reasons", MaskedTextBox5.Text)
            com.Parameters.AddWithValue("@date_apply", MaskedTextBox7.Text)
            com.Parameters.AddWithValue("@notif", MaskedTextBox6.Text)
            com.ExecuteNonQuery()
            con.Close()



this is the code i use before, but it can run..
i dont know the problem clearly cause, here is my before code, but at above i post is the code i had changed.. ..<
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1