Hi,
private void btn_add_Click(object sender, EventArgs e)
{
char sepChar = '/';
string strondate, strondate1, ondate;
string strinvoicedate, strinvoicedate1, invoicedate2;
//SqlConnection con = new SqlConnection("data source=mars-104;intial catalog=marsweb.imageimpacts;integrated security=true");
DBConnection db = new DBConnection();
SqlConnection con = db.opencon();
SqlCommand cmd = new SqlCommand("insert into tbl_temp (invoiceno,particulars,quantity,perprice,amount,orderno,compname,invoicedate,ondate,invoiceid)values(@invoiceno,@particulars,@quantity,@perprice,@amount,@orderno,@compname,@invoicedate,@ondate,@invoiceid)", con);
cmd.Parameters.AddWithValue("@invoiceno", txt_invoiceno.Text);
cmd.Parameters.AddWithValue("@particulars", cmb_particulars.Text);
cmd.Parameters.AddWithValue("@quantity", txt_quantity.Text);
cmd.Parameters.AddWithValue("@perprice", txt_perprice.Text);
cmd.Parameters.AddWithValue("@amount", txt_amount.Text);
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
cmd.Parameters.AddWithValue("@compname", cmb_companyname.Text);
if (txt_invoicedate.Text != null && txt_invoicedate.Text != "")
{
cmd.Parameters.AddWithValue("@invoicedate", txt_invoicedate.Text);
}
else
{
cmd.Parameters.AddWithValue("@invoicedate", DBNull.Value);
}
if (txt_ondate.Text != null && txt_ondate.Text != "")
{
cmd.Parameters.AddWithValue("@ondate", txt_ondate.Text);
}
else
{
cmd.Parameters.AddWithValue("@ondate", DBNull.Value);
}
cmd.Parameters.AddWithValue("@invoiceid", txt_invoiceno.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
con.Close();
txt_quantity.Text = "";
txt_perprice.Text = "";
txt_amount.Text = "";
netamount();
loadparticularsdata();
vatamount();
griddisplay();
}
private void btn_update_Click_1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
SqlCommand cmd = new SqlCommand("update tbl_report2 set compname=@compname,compaddress=@compaddress,orderno=@orderno,ondate=@ondate,invoicedate=@invoicedate,amountstatus=@amountstatus,netamount=@netamount,tamount=@tamount where invoiceno=@id", con);
cmd.Parameters.AddWithValue("@compname", cmb_companyname.Text);
cmd.Parameters.AddWithValue("@compaddress", txt_customeraddress.Text);
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
cmd.Parameters.AddWithValue("@id", id);
if (txt_invoicedate.Text != null && txt_invoicedate.Text != "")
{
cmd.Parameters.AddWithValue("@invoicedate", txt_invoicedate.Text);
}
else
{
cmd.Parameters.AddWithValue("@invoicedate", DBNull.Value);
}
if (txt_ondate.Text != null && txt_ondate.Text != "")
{
cmd.Parameters.AddWithValue("@ondate", txt_ondate.Text);
}
else
{
cmd.Parameters.AddWithValue("@ondate", DBNull.Value);
}
cmd.Parameters.AddWithValue("@amountstatus", rb_paid.Checked);
cmd.Parameters.AddWithValue("@netamount", txt_netamount.Text);
cmd.Parameters.AddWithValue("@tamount", txt_totalamount.Text);
con.Open();
cmd.ExecuteNonQuery();
con .Close ();
SqlConnection con1 = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
SqlCommand cmd1 = new SqlCommand("update tbl_report1 set compname=@compname,orderno=@orderno,invoicedate=@invoicedate,ondate=@ondate where invoiceid=@id", con1);
cmd1.Parameters.AddWithValue("@compname", cmb_companyname.Text);
cmd1.Parameters.AddWithValue("@compaddress", txt_customeraddress.Text);
cmd1.Parameters.AddWithValue("@orderno", txt_orderno.Text);
cmd1.Parameters.AddWithValue("@invoicedate", txt_invoicedate.Text);
cmd1.Parameters.AddWithValue("@ondate", txt_ondate.Text);
cmd1.Parameters.AddWithValue("@id", txt_invoiceno.Text);
con1.Open();
cmd1.ExecuteNonQuery();
con1.Close();
txt_amount.Text = "";
txt_customeraddress.Text = "";
txt_invoicedate.Text = "";
txt_invoiceno.Text = "";
txt_netamount.Text = "";
txt_ondate.Text = "";
txt_orderno.Text = "";
txt_perprice.Text = "";
txt_quantity.Text = "";
txt_totalamount.Text = "";
txt_vat.Text = "";
txt_vatpercentage.Text = "";
MessageBox.Show("updated successfully");
}
Best,
Sudheep.
Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator