我有更新問題。怎麼了?代碼編譯,但是當我點擊按鈕,行 - > cmd.ExecuteNonQuery();沒有工作。SQL更新錯誤
該處ERROR
附加信息:參數化查詢 '(@nmo INT,@ rezerwo INT)UPDATE SET oferty = oferty.miejsca @nmo' 預計參數 '@rezerwo',這是不提供。
public partial class oferty1 : System.Web.UI.Page
SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\ddd\Documents\Visual Studio 2013\Projects\sV1\stopowiczeV1\App_Data\ofety-sV1.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework");
SqlCommand cmd = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
cmd.Connection = cn;
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
var g = GridView1.SelectedRow;
string rezerw = GridView1.DataKeys[g.DataItemIndex]["Idoferty"].ToString();
m = GridView1.SelectedRow.Cells[5].Text;
int nmo = Convert.ToInt32(m);
int rezerwo = Convert.ToInt32(rezerw);
if (GridView1.SelectedRow.Cells[5].Text != "" & GridView1.SelectedRow.Cells[0].Text != "")
{
cn.Open();
nmo--;
cmd = cn.CreateCommand();
cmd.CommandText = ("UPDATE oferty SET oferty.miejsca = @nmo WHERE oferty.idoferty = @rezerwo");
cmd.Parameters.Add(new SqlParameter("@nmo", nmo));
cmd.Parameters.Add(new SqlParameter("@rezerwo", rezerwo));
string snmo = Convert.ToString(nmo);
td.miejsca = snmo;
cmd.ExecuteNonQuery();
cn.Close();
}
db.rezerwacjes.InsertOnSubmit(tc);
db.SubmitChanges();
}
rezerw聲明在哪裏? –
var g = GridView1.SelectedRow; string rezerw = GridView1.DataKeys [g.DataItemIndex] [「Idoferty」]。ToString(); – user3561881