private void calculate_Click(object sender, System.EventArgs e)
{
for(int i=0;i<order.Items.Count;i++)
{
TextBox tb=(TextBox)order.Items[i].FindControl("Quantity");
int qt=Convert.ToInt32(tb.Text);
string ud=(string)Session["userid"];
string od=(string)Session["OrderID"]; SqlConnection myConnection=new SqlConnection("user id=sa;pwd=761110;initial catalog=xjuser");
string sql="update Order1 set Quantity='"+qt+"' where OrderID='"+od+"'and userid='"+ud+"'";
SqlDataCommand myCommand1=new SqlDataCommand (sql,myConnection);
SqlDataAdapter myCommand=new SqlDataAdapter()
myCommand.Selectcommand=myCommand1 DataSet ds=new DataSet();
myCommand.Fill(ds,"aa");
DataTable dt=ds.Tables["aa"];
string s="select * from Order1 where OrderID='"+od+"'and userid='"+ud+"'";
SqlDataAdapter com=new SqlDataAdapter(s,myConnection);
DataSet ds2=new DataSet();
com.Fill(ds2,"as");
DataTable dt2=ds2.Tables["as"];
order.DataSource=dt2;
order.DataBind();
}
{
for(int i=0;i<order.Items.Count;i++)
{
TextBox tb=(TextBox)order.Items[i].FindControl("Quantity");
int qt=Convert.ToInt32(tb.Text);
string ud=(string)Session["userid"];
string od=(string)Session["OrderID"]; SqlConnection myConnection=new SqlConnection("user id=sa;pwd=761110;initial catalog=xjuser");
string sql="update Order1 set Quantity='"+qt+"' where OrderID='"+od+"'and userid='"+ud+"'";
SqlDataCommand myCommand1=new SqlDataCommand (sql,myConnection);
SqlDataAdapter myCommand=new SqlDataAdapter()
myCommand.Selectcommand=myCommand1 DataSet ds=new DataSet();
myCommand.Fill(ds,"aa");
DataTable dt=ds.Tables["aa"];
string s="select * from Order1 where OrderID='"+od+"'and userid='"+ud+"'";
SqlDataAdapter com=new SqlDataAdapter(s,myConnection);
DataSet ds2=new DataSet();
com.Fill(ds2,"as");
DataTable dt2=ds2.Tables["as"];
order.DataSource=dt2;
order.DataBind();
}
int qt=Convert.ToInt32(tb.Text);
能取到这个值吗?
{
for(int i=0;i<order.Items.Count;i++)
{
TextBox tb=(TextBox)order.Items[i].FindControl("Quantity");
int qt=Convert.ToInt32(tb.Text);
string ud=(string)Session["userid"];
string od=(string)Session["OrderID"];SqlConnection myConnection=new SqlConnection("user id=sa;pwd=761110;initial catalog=xjuser");
string sql="update Order1 set Quantity='"+qt+"' where OrderID='"+od+"'and userid='"+ud+"'";
SqlCommand cmd = new SqlCommand(sql,myConnection);
cmd.ExecuteNonQuery();
string s="select * from Order1 where OrderID='"+od+"'and userid='"+ud+"'";
SqlDataAdapter com=new SqlDataAdapter(s,myConnection);
DataSet ds2=new DataSet();
com.Fill(ds2,"as");
order.DataSource=ds2;
order.DataBind();
}
你数据更新思绪有点混乱,帮你改了一下看看能用吗
}
TextBox tb=(TextBox)order.Items[i].FindControl("Quantity");
int qt=Convert.ToInt32(tb.Text);
这个值能取到,可放在更新数据库语句中好像取不到。再帮我看看吧!
在这句话之前设个断点,把得到sql语句放到数据库中去操作一下
int qt=Convert.ToInt32(tb.Text);所取到的值始终是数据库中原有的值,button后无法改变。该如何修改呢?
if(!Page.ISPostBack)
{
}
中
试试看
if(!Page.ISPostBack)
{
}
中之后不应该取不到TextBox的值呀(残念。)
{
}
一般是放在Page_Load()中的,而我要求在button事件中。或许我没有理解你的意思,真不好意思。笨得简直....
解决了!就是要把Page_Load中的数据绑定代码放在if(!Page.ISPostBack)
{
}
中,太感谢了,谢谢你一直给我回复。