473,659 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Erro: Syntax error in INSERT INTO statement

4 New Member
The error is :Syntax error in INSERT INTO statement.
This is my code:
Expand|Select|Wrap|Line Numbers
  1. try
  2.             {
  3.                 DataSet ds1;
  4.                 OleDbConnection ConnSql;
  5.                 OleDbConnection ConnExcel;
  6.                 OleDbDataAdapter da1;
  7.                 OleDbDataAdapter da2;
  8.                 string ConnStringSql = "Provider=sqloledb;Data Source = cst;Initial Catalog = Testido;User ID=sa;Pwd=connect#963;";
  9.  
  10.                 string OutputFilename = "D:\\Misreport.xls";
  11.  
  12.                string ConnStringExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + OutputFilename + ";Extended Properties=\"Excel 8.0;HDR=yes;\"";
  13.  
  14.  
  15. string sqlSelect = "select Day(joborder.CreatedDate)as [DateoftheMonth],CONVERT(varchar(3),joborder.CreatedDate, 100) as [MonthName], joborder.customerid, joborder.jobordernumber, tasklist.employeeid AS recruiterId, employeedetails.empname as recruitername, tasklist.Status, prescreening.prescreeningid, customerdetails.customername, joborder.jobordertitle,joborderprimarymandatoryskills.mandatoryskills,joborder.worklocation,parsedfile.source,parsedfile.candidatename,prescreening.totalexperienceyears,prescreening.totalexperiencemonths,parsedfile.currentorganisation,parsedfile.currentctc,parsedfile.expectedctc,prescreening.noticeperiodmonths,prescreening.noticeperioddays,parsedfile.presentlocation,parsedfile.mobilenumber,prescreening.landlinenumber,parsedfile.candidateemailid,result.statuscode,CONVERT(VARCHAR(10),result.InterviewScheduleDate,110) as [InterviewScheduleDate],convert(varchar,result.InterviewScheduleFromTime, 8) as [InterviewScheduleFromTime],convert(varchar,result.InterviewScheduleToTime,8) as [InterviewScheduleToTime],CONVERT(VARCHAR(10),result.DateOfJoining,110) as [DateOfJoining],result.notes,joborder.createddate from joborder inner join tasklist on joborder.jobordernumber=tasklist.jobordernumber inner join employeedetails on tasklist.employeeid=employeedetails.employeeid inner join customerdetails on joborder.customerid=customerdetails.customerid inner join joborderprimarymandatoryskills on joborder.jobordernumber=joborderprimarymandatoryskills.jobordernumber inner join prescreeningidjobordernumbermapping on joborder.jobordernumber=prescreeningidjobordernumbermapping.jobordernumber and prescreeningidjobordernumbermapping.createdby = employeedetails.employeeid inner join prescreening on prescreeningidjobordernumbermapping.prescreeningid=prescreening.prescreeningid and prescreening.createdby = employeedetails.employeeid inner join parsedfile on prescreening.parsedfileid=parsedfile.parsedfileid  left outer join (select r.prescreeningid as prescreeningid,interviewstatusschedule.statuscode as statuscode, interviewstatusschedule.InterviewScheduleDate,interviewstatusschedule.InterviewScheduleFromTime,interviewstatusschedule.InterviewScheduleToTime,interviewstatusschedule.DateOfJoining, interviewstatusschedule.notes  from(select interviewstatusschedule.prescreeningid,max(interviewstatusscheduleid) as interviewstatusscheduleid from interviewstatusschedule  where interviewstatusschedule.createddate between '4/15/2010' and '7/26/2010' group by  interviewstatusschedule.prescreeningid)as r inner join interviewstatusschedule on r.interviewstatusscheduleid=interviewstatusschedule.interviewstatusscheduleid) as result on prescreening.prescreeningid=result.prescreeningid where joborder.createddate between '4/15/2010' and '7/26/2010' and tasklist.employeeid in ('10003','10004') and tasklist.status='ACCEPTED' and joborder.customerid in('5','6','4')";
  16.  
  17. OleDbCommand objCmd = new OleDbCommand();
  18.                 //Read the Data from database
  19.  
  20.  
  21. ConnSql = new OleDbConnection(ConnStringSql);
  22. ConnExcel = new OleDbConnection(ConnStringExcel);
  23.  
  24. ConnSql.Open();
  25. ConnExcel.Open();
  26.  
  27. da1 = new OleDbDataAdapter();
  28. da1.SelectCommand = new OleDbCommand(sqlSelect);
  29. da1.SelectCommand.Connection = ConnSql;
  30. ds1 = new DataSet();
  31. da1.Fill(ds1);
  32.  
  33.  
  34. for (int iRowCount = 0; iRowCount < ds1.Tables[0].Rows.Count; iRowCount++)
  35.                {
  36.                    strDateoftheMonth = "";
  37.                    strMonthName = "";
  38.                    strcustomerid = "";
  39.                    strjobordernumber = "";
  40.                    strrecruiterId = "";
  41.                    strrecruitername = "";
  42.                    strStatus = "";
  43.                    strPrescreeningId = "";
  44.                    strCustomerName = "";
  45.                    strJobOrderTitle = "";
  46.                    strmandatoryskills = "";
  47.                    strWorkLocation = "";
  48.                    strSource = "";
  49.                    strCandidateName = "";
  50.                    strTotalExperienceYears = "";
  51.                    strTotalExperienceMonths = "";
  52.                    strCurrentOrganisation = "";
  53.                    strCurrentCtc = "";
  54.                    strExpectedCtc = "";
  55.                    strNoticePeriodMonths = "";
  56.                    strNoticePeriodDays = "";
  57.                    strPresentLocation = "";
  58.                    strMobileNumber = "";
  59.                    strLandLineNumber = "";
  60.                    strCandidateEmailId = "";
  61.                    strStatusCode = "";
  62.                    strInterviewScheduleDate = "";
  63.                    strInterviewScheduleFromTime = "";
  64.                    strInterviewScheduleToTime = "";
  65.                    strDateOfJoining = "";
  66.                    strNotes = "";
  67.  
  68.  strDateoftheMonth = ds1.Tables[0].Rows[iRowCount]["DateoftheMonth"].ToString().Trim();
  69.  
  70.                    strMonthName = ds1.Tables[0].Rows[iRowCount]["MonthName"].ToString().Trim();
  71.  
  72.                    strcustomerid = ds1.Tables[0].Rows[iRowCount]["customerid"].ToString().Trim();
  73.  
  74.                    strjobordernumber = ds1.Tables[0].Rows[iRowCount]["jobordernumber"].ToString().Trim();
  75.  
  76.                    strrecruiterId = ds1.Tables[0].Rows[iRowCount]["recruiterId"].ToString().Trim();
  77.  
  78.                    strrecruitername = ds1.Tables[0].Rows[iRowCount]["recruitername"].ToString().Trim();
  79.  
  80.                    strStatus = ds1.Tables[0].Rows[iRowCount]["Status"].ToString().Trim();
  81.  
  82.                    strPrescreeningId = ds1.Tables[0].Rows[iRowCount]["prescreeningid"].ToString().Trim();
  83.  
  84.                    strCustomerName = ds1.Tables[0].Rows[iRowCount]["customername"].ToString().Trim();
  85.  
  86.                    strJobOrderTitle = ds1.Tables[0].Rows[iRowCount]["jobordertitle"].ToString().Trim();
  87.  
  88.                    strmandatoryskills = ds1.Tables[0].Rows[iRowCount]["mandatoryskills"].ToString().Trim();
  89.  
  90.                    strWorkLocation = ds1.Tables[0].Rows[iRowCount]["worklocation"].ToString().Trim();
  91.  
  92.                    strSource = ds1.Tables[0].Rows[iRowCount]["source"].ToString().Trim();
  93.  
  94.                    strCandidateName = ds1.Tables[0].Rows[iRowCount]["candidatename"].ToString().Trim();
  95.  
  96.                    strTotalExperienceYears = ds1.Tables[0].Rows[iRowCount]["totalexperienceyears"].ToString().Trim();
  97.                    strTotalExperienceMonths = ds1.Tables[0].Rows[iRowCount]["totalexperiencemonths"].ToString().Trim();
  98.                    strCurrentOrganisation = ds1.Tables[0].Rows[iRowCount]["currentorganisation"].ToString().Trim();
  99.                    strCurrentCtc = ds1.Tables[0].Rows[iRowCount]["currentctc"].ToString().Trim();
  100.  
  101.                    strExpectedCtc = ds1.Tables[0].Rows[iRowCount]["expectedctc"].ToString().Trim();
  102.  
  103.                    strNoticePeriodMonths = ds1.Tables[0].Rows[iRowCount]["noticeperiodmonths"].ToString().Trim();
  104.                    strNoticePeriodDays = ds1.Tables[0].Rows[iRowCount]["noticeperioddays"].ToString().Trim();
  105.  
  106.                    strPresentLocation = ds1.Tables[0].Rows[iRowCount]["presentlocation"].ToString().Trim();
  107.  
  108.                    strMobileNumber = ds1.Tables[0].Rows[iRowCount]["mobilenumber"].ToString().Trim();
  109.  
  110.                    strLandLineNumber = ds1.Tables[0].Rows[iRowCount]["landlinenumber"].ToString().Trim();
  111.  
  112.                    if (strLandLineNumber == "")
  113.                    {
  114.                        strLandLineNumber = "NULL";
  115.                    }
  116.                    strCandidateEmailId = ds1.Tables[0].Rows[iRowCount]["candidateemailid"].ToString().Trim();
  117.  
  118.                    strStatusCode = ds1.Tables[0].Rows[iRowCount]["statuscode"].ToString().Trim();
  119.  
  120.                    strInterviewScheduleDate = ds1.Tables[0].Rows[iRowCount]["InterviewScheduleDate"].ToString().Trim();
  121.                    strInterviewScheduleFromTime = ds1.Tables[0].Rows[iRowCount]["InterviewScheduleFromTime"].ToString().Trim();
  122.  
  123. if (strInterviewScheduleFromTime == "")
  124.                    {
  125.                        strInterviewScheduleFromTime = "NULL";
  126.  
  127.                    }
  128.  
  129. strInterviewScheduleToTime = ds1.Tables[0].Rows[iRowCount]["InterviewScheduleToTime"].ToString().Trim();
  130.  
  131.                    if (strInterviewScheduleToTime == "")
  132.                    {
  133.                        strInterviewScheduleToTime = "NULL";
  134.                    }
  135. strDateOfJoining = ds1.Tables[0].Rows[iRowCount]["DateOfJoining"].ToString().Trim();
  136.  
  137. strNotes = ds1.Tables[0].Rows[iRowCount]["notes"].ToString().Trim();
  138.                    if (strNotes == "")
  139.                    {
  140.                        strNotes = "NULL";
  141.                    }
  142.  
  143. objCmd.Connection = ConnExcel;
  144.  
  145. objCmd.CommandText = "INSERT INTO Sheet1$(DateoftheMonth, MonthName, customerid, jobordernumber, recruiterId, recruitername, Status, prescreeningid, customername, jobordertitle, mandatoryskills, worklocation, source, candidatename, totalexperienceyears, totalexperiencemonths, currentorganisation, currentctc, expectedctc, noticeperiodmonths, noticeperioddays, presentlocation, mobilenumber, landlinenumber, candidateemailid, statuscode, InterviewScheduleDate, InterviewScheduleFromTime, InterviewScheduleToTime, DateOfJoining, notes) VALUES (" + strDateoftheMonth + "," + strMonthName + "," + strcustomerid + "," + strjobordernumber + "," + strrecruiterId + "," + strrecruitername + "," + strStatus + "," + strPrescreeningId + "," + strCustomerName + "," + strJobOrderTitle + "," + strmandatoryskills + "," + strWorkLocation + "," + strSource + "," + strCandidateName + "," + strTotalExperienceYears + "," + strTotalExperienceMonths + "," + strCurrentOrganisation + "," + strCurrentCtc + "," + strExpectedCtc + "," + strNoticePeriodMonths + "," + strNoticePeriodDays + "," + strPresentLocation + "," + strMobileNumber + "," + strLandLineNumber + "," + strCandidateEmailId + "," + strStatusCode + "," + strInterviewScheduleDate + "," + strInterviewScheduleFromTime + "," + strInterviewScheduleToTime + "," + strDateOfJoining + "," + strNotes + ")";
  146.  
  147.  
  148.  
  149. objCmd.ExecuteNonQuery(); -> Here i face my error:
  150. The error is Syntax error in INSERT INTO statement
  151.  
  152.  
  153. objCmd.Dispose();
  154.  
  155.  
  156. }
  157. ConnSql.Close();
  158. ConnExcel.Close();
  159.  
  160.  
  161.  
  162. }
  163.  
  164.             catch (Exception ex)
  165.             {
  166.                 MessageBox.Show(ex.Message);
  167.             }
Sep 20 '10 #1
1 1406
Where are your parameters for your command object? Are you throwing your variables directly into the INSERT statement?
Oct 1 '10 #2

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

Similar topics

7
6659
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 checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
2
12955
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 'FK_tblOfficePageContent_tblPageContent'. The conflict occurred in database 'CPNCMS', table 'tblPageContent', column 'pageID'. The statement has been terminated. I cant seem to see why I keep getting an error when I do the insert!
3
2813
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write so as to check that it is working correctly it displays just fine. However, whenever I include the password field in one of the SQL INSERT statement's fields I get the following error:
3
1624
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 encounter with the problem to insert 'Password'. It work fine if I did not insert 'Password' but if I did, it will shows that have "syntax error: INSERT INTO..." Did I miss something to write? Please kindly have a look on the cod below, Thank you!
3
2489
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 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
5
2130
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: System.Runtime.InteropServices.COMException: Syntax error in INSERT INTO statement. Source Error: Line 118: MM_editCmd.ActiveConnection = MM_editConnection
9
2762
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 using any reserved words and I have not been able to find my answer googling like crazy. Any help would be greatly appreciated. below is the code that seems to give me the problem. ElseIf NEWMODE = True Then Dim oAdapter As...
0
2338
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 using any reserved words and I have not been able to find my answer googling like crazy. Any help would be greatly appreciated. below is the code that seems to give me the problem. ElseIf NEWMODE = True Then Dim oAdapter As...
0
8335
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.