写了一段更新的代码。大体是,用gridview控件读取全部数据,进行布局,加一个编辑按钮,点击后window.open一个窗口。
利用request.querystring来读出相应的行值到对应的textbox中。然后重新编辑,点击“更新”,用update更新,跟踪的变量全都只是原来的值,而不是改变后的值。执行完毕没有任何错误提示,但却成功完成。
request.querystring过来的ID能得到.
if (Request.QueryString["imid"] != null)
        {
            SqlConnection con = svd.getcon();
            string cmdstr = "select * from cwimdata where imid=@id";
            SqlCommand cmd = new SqlCommand(cmdstr,con);
            cmd.Parameters.AddWithValue("@id",Request.QueryString["imid"].ToString());
            SqlDataReader myread = cmd.ExecuteReader();
            string dj = null;
            if (myread.Read())
            {
                //tt1.Text=myread[2].ToString();
                //tt2.Text = myread[3].ToString();
                //dj = myread[4].ToString();
                //tt4.Text = myread[5].ToString();
                p1 = myread[2].ToString();
                tt1.Text = p1;
                p2 = myread[3].ToString();
                tt2.Text = p2;
                p3 = myread[4].ToString();
                p4 = myread[5].ToString();
                tt3.Text = p3;
                tt4.Text = p4;
                string t5 = myread[6].ToString();
                tt6.Text = DateTime.Now.ToShortDateString();
                tt7.Text = Session["name"].ToString();
                tt7.Enabled = false; tt6.Enabled = false;
                switch (t5)
                {
                    case ("未结算"):
                        dd1.SelectedValue = "未结算";
                        break;
                    case ("结算"):
                        dd1.SelectedValue = "结算";
                        break;
                }
                myread.Close();
                myread.Dispose();
            }//读取数据

解决方案 »

  1.   

    更新事件
     SqlConnection con = svd.getcon();
            string cmd = "update cwimdata set imgoods=@mc,imnum=@sl,imprice=@dj,imtotal=@zj,settlement=@js,imuser=@op where imid=@id";
            SqlCommand scmd = new SqlCommand(cmd, con);
            scmd.Parameters.AddWithValue("@id", Request.QueryString["imid"].ToString());
            scmd.Parameters.AddWithValue("@mc", tt1.Text);
            scmd.Parameters.AddWithValue("@sl", tt2.Text);
            scmd.Parameters.AddWithValue("@dj", tt3.Text);
            scmd.Parameters.AddWithValue("@zj", tt4.Text);
            scmd.Parameters.AddWithValue("@js", dd1.SelectedValue.ToString());
            scmd.Parameters.AddWithValue("@op", Session["name"].ToString());
            try
            {
                scmd.ExecuteNonQuery();
                Response.Write("<script>alert('更新完成');</script>");
               
            }
            catch (Exception ex)
            {
                Response.Write(ex);
            }
      

  2.   

    加非好像弄错了,是无法将改变后的数据update到数据库中,就是更新事件成功执行了却没有得到效果.也没有任何错误
      

  3.   

    更新不成功 多数是SQL语句的问题更新时注意参数类型
      

  4.   

    读取数据的部分加if(!Page.IsPostBack){//读取初始数据的代码},你没有加上这个即使你textbox的值更改过了,点击更新按纽页面回发后又重新从数据库中读取数据,你更改过的textbox又变加原始的值了
      

  5.   

    加了个ispostback解决了,我是新入行的菜鸟程序员,多谢各位的帮助!