private void button8_Click(object sender, EventArgs e) { LogIn li = new LogIn(); string acc = LogIn.acoount; button1.Text = acc + ""; if (textBox4.Text == "") { MessageBox.Show("Please Fill in Supplier No."); } else { try { DataCon.ConnectionDB("ENDROX", "BookStore"); int dindex, x; float y; string sql = "select bid, bqty, bprice from Book where bid ='" + textBox21.Text + "'"; SqlCommand a = new SqlCommand(sql, DataCon.DataConnection); SqlDataReader r = a.ExecuteReader(); while (r.Read()) { string id = r.GetValue(0) + ""; dindex = Convert.ToInt16(id); textBox18.Text = dindex + ""; string idx = r.GetValue(1) + ""; x = Convert.ToInt16(idx); textBox19.Text = x + ""; string idy = r.GetValue(2) + ""; y = Convert.ToSingle(idy); textBox20.Text = y + ""; } r.Close(); int indexx = Convert.ToInt16(textBox1.Text); double gtotal = Convert.ToDouble(textBox2.Text); int eid = Convert.ToInt16(textBox14.Text); int supid = Convert.ToInt16(textBox4.Text); sql = "insert into Import(Importid,Importdate, total, eid, supid) values ('" + indexx + "','" + dateTimePicker1.Text + "','" + gtotal + "','" + eid + "','" + supid + "');"; SqlCommand s = new SqlCommand(sql, DataCon.DataConnection); s.ExecuteNonQuery(); s.Dispose(); int ro = dataGridView1.RowCount - 1; for (int i = 0; i < ro; i++) { if (textBox18.Text == "") { sql = "insert into Book(bid, bname, bqty, bprice, catid, author, Year, location, Attachment) values ('" + dataGridView1.Rows[i].Cells["Book_Code"].Value + "','" + dataGridView1.Rows[i].Cells["Title"].Value + "','" + Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Price"].Value) + "','" + Convert.ToInt16(dataGridView1.Rows[i].Cells["Genre"].Value) + "','" + dataGridView1.Rows[i].Cells["Author"].Value + "','" + dataGridView1.Rows[i].Cells["year"].Value + "','" + dataGridView1.Rows[i].Cells["Location"].Value + "',N'" + dataGridView1.Rows[i].Cells["Attachment"].Value + "');"; SqlCommand sa = new SqlCommand(sql, DataCon.DataConnection); sa.ExecuteNonQuery(); } else { int nbqty = Convert.ToInt16(textBox19.Text) + Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value); sql = "update Book set bqty ='" + nbqty + "' where bid = '" + textBox18.Text + "' ;"; SqlCommand sa = new SqlCommand(sql, DataCon.DataConnection); sa.ExecuteNonQuery(); } sql = "insert into Importdetail(Importid,iqty, iamout, iprice, bid) values ('" + indexx + "','" + Convert.ToInt16(dataGridView1.Rows[i].Cells["Quantity"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Cost"].Value) + "','" + Convert.ToSingle(dataGridView1.Rows[i].Cells["Price"].Value) + "','" + dataGridView1.Rows[i].Cells["Book_Code"].Value + "');"; SqlCommand si = new SqlCommand(sql, DataCon.DataConnection); si.ExecuteNonQuery(); } string message = "Successfully Saved"; string title = " Message "; MessageBox.Show(message, title); textBox2.Text = ""; dateTimePicker1.Value = System.DateTime.Now; dataGridView1.Rows.Clear(); comboBox1.SelectedIndex = -1; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; Visible = false; HistoryImport hi = new HistoryImport(); hi.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }