问题描述
if(Request.QueryString["ID"]==null){stringintoSQL="";intoSQL="insertintowebabout(nFile,nTitle,nHtmlText)values(";intoSQL+=""+txtid.Text+",";intoSQL+="'"+txtitle.Text+"',";intoSQL+="'"+txtContent.Text+"')";dbobj.getcom("insertinto"+intoSQL);publicSqlConnectiongetcon(){stringmyStr=ConfigurationManager.AppSettings["ConnectionString"].ToString();//stringmyStr="server=ADMIN;database=test;Userid=sa;password=123";SqlConnectionSqlcon=newSqlConnection(myStr);returnSqlcon;}#endregion#regionpublicvoidgetcom(stringM_str_Sqlstr){using(SqlConnectionSqlcon=this.getcon()){Sqlcon.Open();SqlCommandSqlcom=newSqlCommand(M_str_Sqlstr,Sqlcon);Sqlcom.ExecuteNonQuery();}}#endregion异常详细信息:System.Data.SqlClient.SqlException:关键字'insert'附近有语法错误。源错误:行39:Sqlcon.Open();行40:SqlCommandSqlcom=newSqlCommand(M_str_Sqlstr,Sqlcon);行41:Sqlcom.ExecuteNonQuery();行42:}行43:}源文件:f:wangzhangscnetApp_CodeClass1.cs行:41堆栈跟踪:[SqlException(0x80131904):关键字'insert'附近有语法错误。]System.Data.SqlClient.SqlConnection.OnError(SqlExceptionexception,BooleanbreakConnection)+109System.Data.SqlClient.SqlInternalConnection.OnError(SqlExceptionexception,BooleanbreakConnection)+57System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObjectstateObj)+207System.Data.SqlClient.TdsParser.Run(RunBehaviorrunBehavior,SqlCommandcmdHandler,SqlDataReaderdataStream,BulkCopySimpleResultSetbulkCopyHandler,TdsParserStateObjectstateObj)+2421System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(StringmethodName,Booleanasync)+192System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResultresult,StringmethodName,BooleansendToPipe)+256System.Data.SqlClient.SqlCommand.ExecuteNonQuery()+117Class1.getcom(StringM_str_Sqlstr)inf:wangzhangscnetApp_CodeClass1.cs:41manage_netset_Aboutedit.btnsave_Click(Objectsender,EventArgse)inf:wangzhangscnetmanagenetsetAboutedit.aspx.cs:65System.Web.UI.WebControls.Button.OnClick(EventArgse)+78System.Web.UI.WebControls.Button.RaisePostBackEvent(StringeventArgument)+100System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(StringeventArgument)+10System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandlersourceControl,StringeventArgument)+13System.Web.UI.Page.RaisePostBackEvent(NameValueCollectionpostData)+36System.Web.UI.Page.ProcessRequestMain(BooleanincludeStagesBeforeAsyncPoint,BooleanincludeStagesAfterAsyncPoint)+2867这是什么原因,,,表为webabout,,,字段为wenFileintnTitlenvarchar(max)nHtmlTextnext
解决方案
解决方案二:
dbobj.getcom("insertinto"+intoSQL);改为:dbobj.getcom(intoSQL);试试看
解决方案三:
1楼正解,还有你下断点调试,把执行的sql字符串拿出来单独调试就明白了。
解决方案四:
你的代码看~~最后执行出来的SQL应该是~~"insertintoinsertintowebabout(nFile,nTitle,nHtmlText)values。。。。“SQL明显语法就不对了嘛!!一楼正解哦!!!
解决方案五:
关键字'insert'附近有语法错误。]报这样的错误肯定是SQL语句写错了一般如果你不知道语句错在哪里调试复制intoSQL字符串到数据库执行下就知道了
解决方案六:
stringintoSQL="";intoSQL="insertintowebabout(nFile,nTitle,nHtmlText)values(";intoSQL+=""+txtid.Text+",";intoSQL+="'"+txtitle.Text+"',";intoSQL+="'"+txtContent.Text+"')";stringtest=intoSQL;dbobj.getcom(intoSQL);//这行设置断点,看看上一行的test值是什么?你就会明白了
很简单