У меня есть Gridview на моей странице. Я могу выбрать каждую строку, которую я хочу, используя флажок, когда i выберите строку в Gridview и нажмите на кнопку Удалить igot эта ошибка «Необходимо объявить скалярную переменную„@Senduserid“» вот Удалить код кнопкиПростое удаление из таблицы, но я получил эту ошибку «Должен объявить скалярную переменную« @Senduserid »«
protected void btnMultipleRowDelete_Click(object sender, EventArgs e)
{
// Looping through all the rows in the GridView
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox checkbox = (CheckBox)row.FindControl("chkRows");
//Check if the checkbox is checked.
//value in the CheckBox's Value property is set as the //value of the delete command's parameter.
while (checkbox.Checked)
{
// Retreive the ID
int ida = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
// Pass the value of the selected Employye ID to the Delete
//These numbers indicate in which order tables shoulde be deleted
/*1*/
new BLL.LoginBLL().Delete(ida);
/*2*/
new BLL.MessageBLL().Delete(ida);
/*3*/
new BLL.JointBLL().Delete(ida);
/*4*/
new BLL.Tempprice().Delete(ida);
/*5*/
new BLL.LotsBLL().Delete(ida);
/*6*/
new BLL.AuctionBLL().Delete(ida);
/*7*/
new BLL.ProfileBLL().DeleteProfile(ida);
checkbox.Checked = false;
}
//refresh the Gridview rows
ShowUsers();
}
}
И код места, где я получил эту ошибку: `
public bool Delete(int Id)
{
using (SqlCommand cmd = new SqlCommand())
{
string text = string.Format("Delete From {0} where {1} = @{1} or {2} [email protected]{2}"
, Common.Data.MessageInfo.TableName
, Common.Data.MessageInfo.SenduseridField
,Common.Data.MessageInfo.RecuseridField);
cmd.CommandText = text;
SqlParameter param = new SqlParameter("@" + Common.Data.MessageInfo.SenduseridField, Id);
param.SqlDbType = SqlDbType.Int;
param = new SqlParameter("@" + Common.Data.MessageInfo.RecuseridField, Id);
param.SqlDbType = SqlDbType.Int;
cmd.Parameters.Add(param);
cmd.Connection = this.GetConnection();
cmd.Connection.Open();
cmd.ExecuteNonQuery();
return true;
}
}
DataBase Отношения
Я идиот справа. –