GridView1点删除 数据删除了 但是提示 必须声明标量变量 "@id"。 在线等谢谢各位高手了..
public partial class delpage : System.Web.UI.Page
{
SqlConnection sqlcon;
string strCon = ConfigurationManager.ConnectionStrings["glDBConnectionString3"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
this.GridView1.DataKeyNames = new string[] { "bpid" };
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int infoID = (int)GridView1.DataKeys[e.RowIndex].Value;
SqlParameter pares = new SqlParameter("@id", SqlDbType.Int, 4);
string Strsql = "delete from bp where bpid=@id";
sqlcon = new SqlConnection(strCon);
if (sqlcon.State.Equals(ConnectionState.Closed))
{ sqlcon.Open(); }
SqlCommand cmd = new SqlCommand(Strsql, sqlcon);
cmd.Parameters.Add(pares);
SqlDataSource1.DeleteCommand = Strsql;
cmd.Parameters["@id"].Value = infoID;
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("<script>alert('删除成功!')</script>");
} sqlcon.Close(); }
————————————————————————————————————错误提示
必须声明标量变量 "@id"。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.Data.SqlClient.SqlException: 必须声明标量变量 "@id"。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[SqlException (0x80131904): 必须声明标量变量 "@id"。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1951450
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849003
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +204
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +175
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +386
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +303
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +89
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +714
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +869