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();
}

解决方案 »

  1.   

    TextBox tb=(TextBox)order.Items[i].FindControl("Quantity");

    int qt=Convert.ToInt32(tb.Text);
    能取到这个值吗?
      

  2.   

    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+"'";
    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();
    }
    你数据更新思绪有点混乱,帮你改了一下看看能用吗

    }
      

  3.   

    谢谢二位,可是数据还是无法更新。
    TextBox tb=(TextBox)order.Items[i].FindControl("Quantity");

    int qt=Convert.ToInt32(tb.Text);
    这个值能取到,可放在更新数据库语句中好像取不到。再帮我看看吧!
      

  4.   

    SqlCommand cmd = new SqlCommand(sql,myConnection);
    在这句话之前设个断点,把得到sql语句放到数据库中去操作一下
      

  5.   

    发现错误,TextBox tb=(TextBox)order.Items[i].FindControl("Quantity");

    int qt=Convert.ToInt32(tb.Text);所取到的值始终是数据库中原有的值,button后无法改变。该如何修改呢?
      

  6.   

    把你用DataSet绑定到DataGrid的那段代码写在
    if(!Page.ISPostBack)
    {
    }

    试试看
      

  7.   

    还是qt无法得到TextBox框中输入的值是吗?
      

  8.   

    很不好意思,我没有qq。要不你发到我的信箱吧。[email protected]
      

  9.   

    把DataGrid绑定DataSet的那一段代码,写在
    if(!Page.ISPostBack)
    {
    }
    中之后不应该取不到TextBox的值呀(残念。)
      

  10.   

    可是if(!Page.ISPostBack)
    {
    }
    一般是放在Page_Load()中的,而我要求在button事件中。或许我没有理解你的意思,真不好意思。笨得简直....
      

  11.   

    to sgsh51(): 
    解决了!就是要把Page_Load中的数据绑定代码放在if(!Page.ISPostBack)
    {
    }
    中,太感谢了,谢谢你一直给我回复。