c#页面程序中,向SQL SERVER 2008 插入记录总是产生Exception消息
我的插入一句如下:
insert into InModelDetail(id,name,gender,passtype,passexpire,prepay,payair,chinaaddress,phone) values(3707,'','Male','1','333443',1000,123,'sdsds','57886')
该语句用SQL SERVER 2008 Management Studio 执行是成功的,但在.aspx.cs代码中总是报错:
列名或所提供值的数目与表定义不匹配。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.Data.SqlClient.SqlException: 列名或所提供值的数目与表定义不匹配。
源错误:
行 107: if (pars != null)
行 108: cmd.Parameters.AddRange(pars);
行 109: return cmd.ExecuteNonQuery();
行 110: }
行 111: }
源文件: D:\Glenn\ERPs -FRAME4\ERP.DAL\DBHelper.cs 行: 109
堆栈跟踪:
[SqlException (0x80131904): 列名或所提供值的数目与表定义不匹配。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +212
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1099
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +2858575
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +470
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +182
ERP.DAL.DBHelper.GetExcuteNonQuery(String cmdTxt, SqlParameter[] pars) in D:\Glenn\ERPs -FRAME4\ERP.DAL\DBHelper.cs:109
ERP.DAL.DBHelper.GetExcuteNonQuery(String cmdTxt) in D:\Glenn\ERPs -FRAME4\ERP.DAL\DBHelper.cs:95
ERP.DAL.InModelService.InsertInModelDetail(InModelDetail inde) in D:\Glenn\ERPs -FRAME4\ERP.DAL\InModelService.cs:38
ERP.BLL.InDeptModelsManager.InsertInModelDetail(InModelDetail inmodeldetail) in D:\Glenn\ERPs -FRAME4\ERP.BLL\InDeptModelsManager.cs:15
Master_Default.btnClickOK_Click(Object sender, EventArgs e) in d:\Glenn\ERPs -FRAME4\WEB\InDepot.aspx.cs:121
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
--------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.5456; ASP.NET 版本:2.0.50727.5456
源代码如下:
protected void btnClickOK_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(this.txtStoreID.Text.Trim());
string StoreDate = this.txtStoreDate.Text;
string StoreType = this.ddlStoreType.SelectedItem.Text.Trim();
string StorePlace = this.ddlStorePlace.SelectedItem.Text;
string Users = this.ddlUsers.SelectedItem.Text;
string BuyDate = this.txtBuyDate.Text.Trim();
string BuyDepartment = this.ddlDepartment.SelectedItem.Text;
string BuyMan = this.txtBuyMan.Text.Trim();
string Ratify = this.txtRatify.Text.Trim();
string Remark = this.txtRemark.Text.Trim();
string StoreName = this.txtStoreName.Text.Trim();//glenn
dp.Id = id;