The error is :Syntax error in INSERT INTO statement.
This is my code:
This is my code:
Code:
try
{
DataSet ds1;
OleDbConnection ConnSql;
OleDbConnection ConnExcel;
OleDbDataAdapter da1;
OleDbDataAdapter da2;
string ConnStringSql = "Provider=sqloledb;Data Source = cst;Initial Catalog = Testido;User ID=sa;Pwd=connect#963;";
string OutputFilename = "D:\\Misreport.xls";
string ConnStringExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + OutputFilename + ";Extended Properties=\"Excel 8.0;HDR=yes;\"";
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')";
OleDbCommand objCmd = new OleDbCommand();
//Read the Data from database
ConnSql = new OleDbConnection(ConnStringSql);
ConnExcel = new OleDbConnection(ConnStringExcel);
ConnSql.Open();
ConnExcel.Open();
da1 = new OleDbDataAdapter();
da1.SelectCommand = new OleDbCommand(sqlSelect);
da1.SelectCommand.Connection = ConnSql;
ds1 = new DataSet();
da1.Fill(ds1);
for (int iRowCount = 0; iRowCount < ds1.Tables[0].Rows.Count; iRowCount++)
{
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 = "";
strDateoftheMonth = ds1.Tables[0].Rows[iRowCount]["DateoftheMonth"].ToString().Trim();
strMonthName = ds1.Tables[0].Rows[iRowCount]["MonthName"].ToString().Trim();
strcustomerid = ds1.Tables[0].Rows[iRowCount]["customerid"].ToString().Trim();
strjobordernumber = ds1.Tables[0].Rows[iRowCount]["jobordernumber"].ToString().Trim();
strrecruiterId = ds1.Tables[0].Rows[iRowCount]["recruiterId"].ToString().Trim();
strrecruitername = ds1.Tables[0].Rows[iRowCount]["recruitername"].ToString().Trim();
strStatus = ds1.Tables[0].Rows[iRowCount]["Status"].ToString().Trim();
strPrescreeningId = ds1.Tables[0].Rows[iRowCount]["prescreeningid"].ToString().Trim();
strCustomerName = ds1.Tables[0].Rows[iRowCount]["customername"].ToString().Trim();
strJobOrderTitle = ds1.Tables[0].Rows[iRowCount]["jobordertitle"].ToString().Trim();
strmandatoryskills = ds1.Tables[0].Rows[iRowCount]["mandatoryskills"].ToString().Trim();
strWorkLocation = ds1.Tables[0].Rows[iRowCount]["worklocation"].ToString().Trim();
strSource = ds1.Tables[0].Rows[iRowCount]["source"].ToString().Trim();
strCandidateName = ds1.Tables[0].Rows[iRowCount]["candidatename"].ToString().Trim();
strTotalExperienceYears = ds1.Tables[0].Rows[iRowCount]["totalexperienceyears"].ToString().Trim();
strTotalExperienceMonths = ds1.Tables[0].Rows[iRowCount]["totalexperiencemonths"].ToString().Trim();
strCurrentOrganisation = ds1.Tables[0].Rows[iRowCount]["currentorganisation"].ToString().Trim();
strCurrentCtc = ds1.Tables[0].Rows[iRowCount]["currentctc"].ToString().Trim();
strExpectedCtc = ds1.Tables[0].Rows[iRowCount]["expectedctc"].ToString().Trim();
strNoticePeriodMonths = ds1.Tables[0].Rows[iRowCount]["noticeperiodmonths"].ToString().Trim();
strNoticePeriodDays = ds1.Tables[0].Rows[iRowCount]["noticeperioddays"].ToString().Trim();
strPresentLocation = ds1.Tables[0].Rows[iRowCount]["presentlocation"].ToString().Trim();
strMobileNumber = ds1.Tables[0].Rows[iRowCount]["mobilenumber"].ToString().Trim();
strLandLineNumber = ds1.Tables[0].Rows[iRowCount]["landlinenumber"].ToString().Trim();
if (strLandLineNumber == "")
{
strLandLineNumber = "NULL";
}
strCandidateEmailId = ds1.Tables[0].Rows[iRowCount]["candidateemailid"].ToString().Trim();
strStatusCode = ds1.Tables[0].Rows[iRowCount]["statuscode"].ToString().Trim();
strInterviewScheduleDate = ds1.Tables[0].Rows[iRowCount]["InterviewScheduleDate"].ToString().Trim();
strInterviewScheduleFromTime = ds1.Tables[0].Rows[iRowCount]["InterviewScheduleFromTime"].ToString().Trim();
if (strInterviewScheduleFromTime == "")
{
strInterviewScheduleFromTime = "NULL";
}
strInterviewScheduleToTime = ds1.Tables[0].Rows[iRowCount]["InterviewScheduleToTime"].ToString().Trim();
if (strInterviewScheduleToTime == "")
{
strInterviewScheduleToTime = "NULL";
}
strDateOfJoining = ds1.Tables[0].Rows[iRowCount]["DateOfJoining"].ToString().Trim();
strNotes = ds1.Tables[0].Rows[iRowCount]["notes"].ToString().Trim();
if (strNotes == "")
{
strNotes = "NULL";
}
objCmd.Connection = ConnExcel;
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 + ")";
objCmd.ExecuteNonQuery(); -> [B]Here i face my error:
The error is Syntax error in INSERT INTO statement[/B]
objCmd.Dispose();
}
ConnSql.Close();
ConnExcel.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Comment