插入数据时出现问题 [英] Problem in inserting data

查看:81
本文介绍了插入数据时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在表中插入数据时,它给了我语法错误
代码是

when i am trying to insert a data in a table it gives me syntax error
code is

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!

推荐答案

我认为您缺少日期格式和数字/日期的数据类型,文本框可能为空/日期格式可能错误. br/> 请提供错误消息,以便我为您提供更好的答案.
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.


查看您的列名称:"E-MailId"可能是造成此问题的原因.在表定义中更改它(一个好主意),或者记住每次使用它时都要对其进行转义:
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:
INSERT INTO Company(Phone2, [E-MailId], VATTIN) VALUES (...)



顺便说一句:不要串联字符串来构建SQL命令.它使您对意外或蓄意的SQL注入攻击敞开大门,这可能会破坏整个数据库.可以使用参数化查询.



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.


您可能会缺少任何值的数据类型.对于每个值,请使用db进行检查,然后通过解析将其发送出去.检查文本框值不能为空.我建议使用参数化查询代替.
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.


这篇关于插入数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆