Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i am trying to insert a data in a table it gives me syntax error
code is
C#
string str="insert into Company(CompanyName,Address1,Address2,Address3,City,State,PinCode,Phone1,Phone2,E-MailId,VATTIN,PinNo,TNGST,CST,ITNo,StartDate,UptoDate) values('"+txtName.Text+"','"+txtAddrs1.Text+"','"+txtAddrs2.Text+"','"+txtAddrs3.Text+"','"+txtCity.Text+"','"+txtState.Text+"',"+txtPinCode.Text+",'"+txtPhone1.Text+"','"+txtPhone2.Text+"','"+txtEmail.Text+"','"+txtVattin.Text+"','"+txtPinNo.Text+"','"+txtTngst.Text+"','"+txtCst.Text+"','"+txtItNo.Text+"','"+dteStartDate.Text+"','"+dteUptoDate.Text+"')";

plz help me!
Posted
Updated 1-Nov-12 23:14pm
v2
Comments
sarathtamil 2-Nov-12 4:36am    
check the data definition of the each column in the table
sarathtamil 2-Nov-12 4:37am    
what error ?
Manoj Kumar Choubey 2-Nov-12 5:18am    
What was the error message ?

I think you are missing date format and data type of number/date , text box may be empty / and date format may be wrong .
Please provide the error message so i can give you better answer.
 
Share this answer
 
Look at you tcolumn names: "E-MailId" is probably causing the problem. Either change it in the table definition (good idea) or remember to escape it each time you use it:
SQL
INSERT INTO Company(Phone2, [E-MailId], VATTIN) VALUES (...)


BTW: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 
You may missing datatype for any of the values.Check it with db for each and every value and send the values by parsing it. Check textbox values should not be empty.I suggest to use parameterized queries instead of this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900