how can i avoid the previous data in gridview?

Posted by Sudheep.grandhe under C# on 1/7/2012 | Points: 10 | Views : 1111 | Status : [Member] | Replies : 1
Hi,

I am developing windows applications.in my form the user enter the details and click add button it will display that current record only.But my problem is it displays previous records also.how can i avoid this.Please do the needful.


private void btn_add_Click(object sender, EventArgs e)
{
if (!Validation())
return;
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
if (con.State == System.Data.ConnectionState.Closed)
con.Open();

SqlCommand cmd1 = new SqlCommand("insert into tbl_report2(compname,compaddress,invoiceno,orderno,invoicedate,ondate,amountstatus)values(@compname,@compaddress,@invoiceno,@orderno,@invoicedate,@ondate,@amountstatus)", con);
cmd1.Parameters.AddWithValue("@compname", cmb_companyname.Text);
cmd1.Parameters.AddWithValue("@compaddress", txt_customeraddress.Text);
cmd1.Parameters.AddWithValue("@invoiceno", txt_invoiceno.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("@amountstatus", rb_paid.Checked);

if (con.State == System.Data.ConnectionState.Closed)
{
con.Open();
}
cmd1.ExecuteNonQuery();
con.Close();
SqlCommand cmd = new SqlCommand("insert into tbl_report1 (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();//using this function i am displying the data in gridview.

}

Best,
Sudheep.



Responses

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

Gridview binded dataset or datatable put null value after bind them.

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response