By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

syntax error insert into statement

P: 1
hello guys
I am new here and in programing
I have this program that I am designing am using Visual studio 2010 and ms access 2010. am using ms access as a data base i have successfully designed the form and runs it but when ever I try to save to my data base it shows me "syntax error insert into statement" and I have checked all I know. mind you I use text box all through
thanks in anticipation
here is my code

Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.Collections.Generic
  3. Imports System.ComponentModel
  4. Imports System.Data
  5. Imports System.Data.SqlClient
  6. Imports System.Drawing
  7. Imports System.Text
  8. Imports System.Windows.Forms
  9. Imports System.Data.OleDb
  10. Imports System.Data.OleDb.OleDbConnection
  11. Public Class Form1
  12.     Dim dbSave As New OleDb.OleDbCommand
  13.     Dim dbConnect As New OleDb.OleDbConnection
  14.     Dim sReader As OleDb.OleDbDataReader
  15.     Dim Line As String = Environment.NewLine
  16.     Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
  17.  
  18.     End Sub
  19.  
  20.     Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpayslipno.TextChanged
  21.  
  22.     End Sub
  23.  
  24.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  25.         Try
  26.             dbConnect.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Admin\Desktop\pastor work\WindowsApplication6\Database9.accdb"
  27.             dbconnect.Open()
  28.         Catch ex As Exception
  29.             MessageBox.Show(ex.Message + Line + "Main Database Not Found" + Line + "Check form_AccessMaintenance source code" + Line + "Database Path", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  30.             Me.Close()
  31.         End Try
  32.     End Sub
  33.  
  34.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  35.         Dim xempi, xempn, xdept, xpsn, xbspm, xpp, xsp, xpd, xovtc, xshc, xtall, xtxp, xtam, xtram, xmisp, xld, xla, xpfi, xesi, xtax, xmec, xcoc, xlcam, xmisd, xremk As String
  36.         xempi = txtemployid.Text
  37.         xempn = txtemployname.Text
  38.         xdept = txtdepartment.Text
  39.         xpsn = txtpayslipno.Text
  40.         xbspm = txtBasicsalary.Text
  41.         xpp = txtpayperiod.Text
  42.         xsp = txtSalaryperiod.Text
  43.         xpd = txtpaiddate.Text
  44.         xovtc = txtOvertimec.Text
  45.         xshc = txtshiftcharge.Text
  46.         xtall = txttotalal.Text
  47.         xtxp = txttotalexp.Text
  48.         xtam = txttotalam.Text
  49.         xtram = txttrainingam.Text
  50.         xmisp = txtmiscpay.Text
  51.         xld = txtleaveday.Text
  52.         xla = txtleaveam.Text
  53.         xpfi = txtpfi.Text
  54.         xesi = txtesi.Text
  55.         xtax = txttaxam.Text
  56.         xmec = txtmesscha.Text
  57.         xcoc = txtconveyancec.Text
  58.         xlcam = txtlcelamount.Text
  59.         xmisd = txtmiscdeduction.Text
  60.         xremk = txtremark.Text
  61.  
  62.  
  63.         If txtemployid.Text = "" Then
  64.  
  65.         End If
  66.  
  67.         Try
  68.  
  69.             xempi = txtemployid.Text
  70.             xempn = txtemployname.Text
  71.             dbSave.CommandText = "INSERT INTO Table1(EmployeeID, EmployeeName, Department, PayslipNo,Basicsalaryperm, Payperiod, SalaryPeriod, PAidDays, Overtimecharge, ShiftCharge, TotalAllawance, TotalExpenses, TotalAmount, TrainingAmount, MiscPAyment, LeaveAmount, PFI, ESI, TaxAmount, MessAmount, COnveyanceCharge, LC/ELAmount, MiscDeduction, Remarks) VALUES ('" & xempi & "','" & xempn & "','" & xdept & "','" & xpsn & "','" & xbspm & "','" & xpp & "','" & xsp & "','" & xpd & "','" & xovtc & "','" & xshc & "','" & xtall & "','" & xtxp & "','" & xtam & "','" & xtram & "','" & xmisp & "','" & xld & "','" & xla & "','" & xpfi & "','" & xesi & "','" & xtax & "','" & xmec & "','" & xcoc & "','" & xlcam & "','" & xmisd & "','" & xremk & "')"
  72.             'MsgBox(dbInsert.CommandText)                                                                                                                   
  73.             dbSave.CommandType = CommandType.Text
  74.             dbSave.Connection = dbConnect
  75.             dbSave.ExecuteNonQuery()
  76.             MessageBox.Show("Record Posted Succesfully for " + Line + txtemployid.Text)
  77.         Catch ex As Exception
  78.             MessageBox.Show(ex.Message)
  79.         End Try
  80.  
  81.     End Sub
  82.  
  83.     'Private Function dbSave() As Object
  84.     '    Throw New NotImplementedException
  85.     'End Function
  86.  
  87. End Class
Jul 10 '13 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,374
You specified 24 fields yet you are trying to insert 25 fields.

Also your LC/ELAmount has a non-standard field character so you will need to tell SQL that it's a field name by surrounding it in square brackets.
Jul 10 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.