返回首页

我在SQL
桌面应用程序错误问题是SQL查询Sytax错误。

问题是由于日期时间选择器..

查询是

 MAcmd = MAconn.CreateCommand();

                MAcmd.CommandText = "INSERT INTO maintable VALUES('" + txtfileno.Text + "','" + txtname.Text + "','" + txtfathername.Text + "','" + txtaddress.Text + "','" + dateTimePicker1.Text + "','" + txtperscription.Text + "'," + txtfee.Text + ")";

                MAcmd.ExecuteNonQuery();

                MessageBox.Show("Information Inserted Successfully");

                MAconn.Close();


我做客户的日期格式为

{C}
在数据库中的日期字段是日期/时间类型的

其插入插入文本框日期查询工作不错,但我希望将它添加使用日期时间选择器。

回答

评论会员:标记Nischalke 时间:2012/02/06
从不,曾经使用未经验证的用户在SQL语句的输入。你应该使用一个存储过程,或者至少是一个参数化查询。这也将帮助你找到问题。

此外,使用而非字符串串联不可读的混乱的String.Format如果你必须形成一个字符串值:一个拉赫曼。穆罕默德
评论会员:游客 时间:2012/02/06
至于提到马克对SP或PQ,是SQL查询的方式来处理。此外,通过您提供的查询时装展示,有一个单引号(')失踪codepre+spanclass="code-string""/spanspanclass="code-string"',"/span+txtfee.Text+spanclass="code-string""/spanspanclass="code-string")"/span;/pre/codetxtfee(承担的txtfee类型是在数据库的文本)。这样的基础上,{C3的可能解决您的问题。最后,我也强烈建议你使用PQ,请看看imgsrc=http://www.orcode.com/img/ico/smiley_smile.gif]。{S0}