المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : problem in inserting a record in data base tale



C# Programming
04-27-2009, 03:02 PM
hi
in my project i convert excel file in xml and then upload the file in data base . here i use SQL Server 2005. In my excel file consist one record D'Souza when such name comes program throw run time exception as Incorrect syntax near 'Souza
i use following query for insert a record

string istr = "insert into sheet1(Personnel_Area,EE_Grp,Employee_Group,ESgrp,Employee_Subgroup,Cost_ctr,Cos

t_Center,PSubarea,Personnel_Subarea,Peres_no,Personel_Number,Designation,D

esigna,Pos,Age_of_Employee,Birthdate,Complete_name)values('" + Convert.ToString(dataGridView1.Rows[i].Cells[0].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[1].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[2].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[3].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[4].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[5].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[6].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[7].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[8].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[9].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[10].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[11].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[12].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[13].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[14].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[17].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[18].Value.ToString()) + "')";