sql insert语句往数据库插入数据出错
李国宝 2014-02-21 10:50:04 insert语句插入语句中,某字段数据类型为字符型,取得控件text值后,text值中有''存在,插入出错。
求解决办法。
代码:
string art_sql = "INSERT INTO [it].[dbo].[Article]([ArticleTitle],[ArticleContent],[UserId],[ArticleTime],[ArticleTypeId])VALUES('" + txtTitle.Text + "','"+Convert.ToString(txtCKEditor.Text.ToString())+"'," + Convert.ToInt32(lblUserId.Text) + ",'" + Convert.ToDateTime(lblTime.Text) + "'," + Convert.ToInt32(ddlArticleType.SelectedValue) + ")";
如txtCKEditor.Text中带有',无法正常插入。