473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

syntax error insert into statement

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
1 1630
Rabbit
12,516 Expert Mod 8TB
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

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

Similar topics

7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
2
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error from the code below! Error: INSERT statement conflicted with COLUMN FOREIGN KEY constraint...
3
by: jinhy82 | last post by:
Hi! I am currently creating a Registration form which contained: UserID Password, FirstName and LastName. These details would be inserted into Ms Access when I click submi button. But I...
3
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
1
by: vasanth chandrasekaran | last post by:
The error is :Syntax error in INSERT INTO statement. This is my code: try { DataSet ds1; OleDbConnection ConnSql; OleDbConnection...
9
by: Ed Pisa | last post by:
Hello, I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not...
0
by: Ed Pisa | last post by:
Hello, I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.