コード例 #1
0
        private void update_btn_Click(object sender, EventArgs e)
        {
            string prodlineid = txt_prodlineID.Text;
            string prodline   = txt_prodline.Text;

            if (txt_prodlineID.Text == "" /*|| txt_prodname.Text == "" || cb_ProdLine.Text == "" || cb_netwt.Text == "" || cb_unit.Text == ""*/)
            {
                NoRecordstoUpdate NRU = new NoRecordstoUpdate();
                NRU.Show();
            }

            else
            {
                try
                {
                    con.Open();
                    sda = new SqlDataAdapter("UPDATE productline_tbl SET  Product_Line = '" + prodline + "' where ProductLine_ID = '" + prodlineid + "'", con);


                    dt = new DataTable();
                    sda.Fill(dt);
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                txt_prodlineID.Clear();
                txt_prodline.Clear();
                loadtabletodatagridview();
            }
        }
コード例 #2
0
        private void updatedata_Click(object sender, EventArgs e)
        {
            string prodid   = txt_prodID.Text;
            string prodname = txt_prodname.Text + cb_netwt.Text;
            string prodline = cb_ProdLine.Text;
            string produnit = cb_unit.Text;
            string prodsupp = cb_supplier.Text;
            int    mrkup    = Convert.ToInt32(nud_markUp.Value);
            string price    = txt_Price.Text;
            string pp       = txt_perpiece.Text;


            if (txt_prodID.Text == "" /*|| txt_prodname.Text == "" || cb_ProdLine.Text == "" || cb_netwt.Text == "" || cb_unit.Text == ""*/)
            {
                NoRecordstoUpdate NRU = new NoRecordstoUpdate();
                NRU.Show();
            }

            else
            {
                try
                {
                    con.Open();
                    sda = new SqlDataAdapter("UPDATE product_tbl SET Product_Name = '" + prodname + "', ProductLineID = (Select ProductLineID from productline_tbl where Product_Line = '" + prodline + "'), UnitID = (Select UnitID from unit_tbl where Unit_Description = '" + produnit + "'), SupplierID = (Select SupplierID from supplier_tbl where Supplier_Name = '" + prodsupp + "'),Mark_Up = '" + mrkup + "', Price = '" + price + "', Price_per_piece = '" + pp + "'  where Product_ID = '" + prodid + "'", con);


                    dt = new DataTable();
                    sda.Fill(dt);
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                txt_prodID.Clear();
                txt_prodname.Clear();
                cb_netwt.ResetText();
                cb_ProdLine.ResetText();
                cb_unit.ResetText();
                cb_supplier.ResetText();
                txt_Price.Clear();
                txt_perpiece.Clear();
                loadtabletodatagridview();
            }
        }