shahram176
سه شنبه 23 دی 1393, 23:59 عصر
سلام
من تو گرید ویو یک دکمه گذاشتم که در کد بیهایندش نوشتم:
{
Button b = (Button)sender;
string aid = b.CommandArgument;
int a = int.Parse(aid);
string strConnection = WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ToString();
SqlConnection con = new SqlConnection(strConnection);
string stCmd = "update tPayment set status=~status , amount=@amount where pid=@pid ";
SqlCommand cnd = new SqlCommand(stCmd, con);
cnd.Parameters.AddWithValue("@pid", a);
cnd.Parameters.AddWithValue("@amount", 0);
con.Open();
cnd.ExecuteNonQuery();
con.Close();
GridView1.DataBind();
string username = string.Empty;
float amount = 0;
float Credit = 0;
System.Web.UI.WebControls.Button lbtn = (Button)sender;
if (lbtn != null)
{
GridViewRow row = lbtn.NamingContainer as GridViewRow;
if (row != null)
{
Label lblusername = row.FindControl("lbl_username") as Label;
Label lbl_Credit = row.FindControl("lbl_Credit") as Label;
Label lblamount = row.FindControl("lbl_amount") as Label;
if (lblusername != null)
{
username = lblusername.Text;
}
if (lbl_Credit != null)
{
Credit = float.Parse(lbl_Credit.Text);
}
if (lblamount != null)
{
amount = float.Parse(lblamount.Text);
}
}
}
strConnection = WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ToString();
con = new SqlConnection(strConnection);
string strCmd = "update tUser set Credit=@Credit where username=@username ";
SqlCommand cmmd = new SqlCommand(strCmd, con);
cmmd.Parameters.AddWithValue("@Credit", Credit + amount);
cmmd.Parameters.AddWithValue("@username", username);
con.Open();
cmmd.ExecuteNonQuery();
GridView1.DataBind();
con.Close();
}
وقتی پروژه را اجرا میکنم با کلیک روی دکمه هیچ اتفاقی نمیفته مشکل چیه؟
من تو گرید ویو یک دکمه گذاشتم که در کد بیهایندش نوشتم:
{
Button b = (Button)sender;
string aid = b.CommandArgument;
int a = int.Parse(aid);
string strConnection = WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ToString();
SqlConnection con = new SqlConnection(strConnection);
string stCmd = "update tPayment set status=~status , amount=@amount where pid=@pid ";
SqlCommand cnd = new SqlCommand(stCmd, con);
cnd.Parameters.AddWithValue("@pid", a);
cnd.Parameters.AddWithValue("@amount", 0);
con.Open();
cnd.ExecuteNonQuery();
con.Close();
GridView1.DataBind();
string username = string.Empty;
float amount = 0;
float Credit = 0;
System.Web.UI.WebControls.Button lbtn = (Button)sender;
if (lbtn != null)
{
GridViewRow row = lbtn.NamingContainer as GridViewRow;
if (row != null)
{
Label lblusername = row.FindControl("lbl_username") as Label;
Label lbl_Credit = row.FindControl("lbl_Credit") as Label;
Label lblamount = row.FindControl("lbl_amount") as Label;
if (lblusername != null)
{
username = lblusername.Text;
}
if (lbl_Credit != null)
{
Credit = float.Parse(lbl_Credit.Text);
}
if (lblamount != null)
{
amount = float.Parse(lblamount.Text);
}
}
}
strConnection = WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ToString();
con = new SqlConnection(strConnection);
string strCmd = "update tUser set Credit=@Credit where username=@username ";
SqlCommand cmmd = new SqlCommand(strCmd, con);
cmmd.Parameters.AddWithValue("@Credit", Credit + amount);
cmmd.Parameters.AddWithValue("@username", username);
con.Open();
cmmd.ExecuteNonQuery();
GridView1.DataBind();
con.Close();
}
وقتی پروژه را اجرا میکنم با کلیک روی دکمه هیچ اتفاقی نمیفته مشکل چیه؟