评论

  • using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;

    public partial class ProStockEarning : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (Session["pass"] == null)
    Response.Redirect("Default.aspx");
    if (!Page.IsPostBack)
    {
    bind();
    }
    }

    public void bind()
    {
    GridView1.AllowPaging = true;
    GridView1.PageSize = 5;
    string settings = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("qiyeguanlixitong.mdb");
    OleDbConnection con = new OleDbConnection(settings);
    con.Open();
    string Str = "SELECT [商品编号],[库存数量],[库存预警量] FROM [ProStock]";
    OleDbDataAdapter ada = new OleDbDataAdapter(Str, con);
    DataSet ds = new DataSet();
    ada.Fill(ds);
    GridView1.DataSource=ds;
    GridView1.DataBind();
    ButtonField button = new ButtonField();
    button.HeaderText = "选择";
    button.Text = "选择";
    button.CommandName = "select";
    GridView1.Columns.Add(button);
    GridView1.Dispose();
    con.Close();
    }
    protected void Stock_Change_Click(object sender, EventArgs e)
    {
    try
    {
    string settings = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("qiyeguanlixitong.mdb");
    OleDbConnection mycon = new OleDbConnection(settings);
    mycon.Open();
    OleDbCommand mycom = new OleDbCommand();
    mycom.Connection = mycon;
    mycom.CommandText = "Select * From ProStock";
    OleDbDataAdapter myda= new OleDbDataAdapter();
    myda.SelectCommand = mycom;
    DataSet myds = new DataSet();
    myda.Fill(myds);
    OleDbCommandBuilder mycmb = new OleDbCommandBuilder();
    mycmb.DataAdapter = myda;
    OleDbDataReader reader = mycom.ExecuteReader();
    int i= 0;
    while (reader.Read())
    {
    if (reader[0].ToString()==TextBox1.Text)
    break;
    i++;
    }
    DataRow dr = myds.Tables[0].Rows[i];
    dr["库存预警量"] = TextBox3.Text;
    reader.Close();
    myda.Update(myds);
    mycon.Close();
    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    finally
    {
    Response.Redirect("ProStockEarning.aspx");
    }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
    GridView1.PageIndex = e.NewPageIndex;
    bind(); //重新绑定GridView数据的函数
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    bind();
    if (e.CommandName == "select")
    {
    TextBox[] txt = new TextBox[] { TextBox1, TextBox2, TextBox3 };
    int i;
    for (i = 0; i < 3; i++)
    {
    if (txt[i].Text != "")
    txt[i].Text.Remove(0);
    }
    int m;
    m = Convert.ToInt32(e.CommandArgument);
    GridViewRow row = GridView1.Rows[m];
    TextBox1.Text = row.Cells[1].Text;
    TextBox2.Text = row.Cells[2].Text;
    TextBox3.Text = row.Cells[3].Text;
    }
    }
    }
    这个怎么实现??急啊!