我有一个表“燃料”,它有一行,这是一个主键,名为“fuel_id”,该字段是自动增量。还有3行是典型的字符串。当我插入数据时,它会抛出一个异常,即参数索引超出范围。任何帮助将不胜感激。
只是为了确保我的插入字符串是:
"INSERT INTO fuels (fuel_id, fuel_type, price, date) VALUES (?, ?, ?, ?)"
堆栈追踪:
[IndexOutOfRangeException: Parameter index is out of range.]
MySql.Data.MySqlClient.MySqlParameterCollection.CheckIndex(Int32 index) +117
MySql.Data.MySqlClient.MySqlParameterCollection.InternalGetParameter(Int32 index) +41
MySql.Data.MySqlClient.MySqlParameterCollection.get_Item(Int32 index) +41
MySql.Data.MySqlClient.Statement.SerializeParameter(MySqlParameterCollection parameters, MySqlPacket packet, String parmName, Int32 parameterIndex) +138
MySql.Data.MySqlClient.Statement.InternalBindParameters(String sql, MySqlParameterCollection parameters, MySqlPacket packet) +710
MySql.Data.MySqlClient.Statement.BindParameters() +155
MySql.Data.MySqlClient.Statement.Execute() +33
MySql.Data.MySqlClient.PreparableStatement.Execute() +77
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +1925
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() +37
MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() +164
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +380
System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +399
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +81
Telerik.Web.UI.GridTableView.PerformInsert(GridEditableItem editedItem, Boolean suppressRebind) +370
Telerik.Web.UI.GridTableView.PerformInsert(GridEditableItem editedItem) +44
Telerik.Web.UI.GridTableView.PerformInsert() +73
Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +6245
Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +205
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +71
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
Telerik.Web.UI.GridEditFormItem.OnBubbleEvent(Object source, EventArgs e) +372
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +156
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9643314
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
答案 0 :(得分:1)
试试这个
INSERT INTO fuels (fuel_type, price, date) VALUES (?, ?, ?)
当作为自动增量的表列不包含在插入查询中时,当您通过此查询插入记录时,将自动插入fuel_id列值。