Hi,
in my form automatically it shows the records by default for a particular company only .if i select different names it shows repetely one company name only.Here i am posting the sample code.if you are not getting.please let me know.please do the needful.
public partial class DateSearch : Form
{
int id1=1;//i am declare here as '1' because of this only it shows the repetly same company name.otherwise if i declare as int id=0;it shows no data.that's reason i declared like that.
public DateSearch()
{
InitializeComponent();
}
private void btn_datesearch_Click(object sender, EventArgs e)
{
GridView1.Controls.Clear();
GridView2.Controls.Clear();
reportsgridview();
}
public void reportsgridview()
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select compname,compaddress,invoiceno,orderno,convert(varchar,ondate,105)as [ondate],convert(varchar,invoicedate,105)as [invoicedate],amountstatus,netamount,netvat,tamount from tbl_report2 where invoicedate between @startdate and @enddate order by invoicedate asc", con);
cmd.Parameters.AddWithValue("@startdate", Convert.ToDateTime(txt_startdate.Text));
cmd.Parameters.AddWithValue("@enddate", Convert.ToDateTime(txt_enddate.Text));
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
}
else
{
MessageBox.Show("no record found");
GridView1.DataSource = null;
}
SqlConnection con1 = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd1 = new SqlCommand("select particulars,orderno,quantity,perprice,amount from tbl_report1 where invoiceid=@id1", con1);
cmd1.Parameters.AddWithValue("@id1",id1);//here i am passing the parameter also but it wont shows the records when i declare int id=0 it wont shows if i declare as int id=1 it shows only one record repetly if i select any another company name also .it shows that '1' record
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count > 0)
{
GridView2.DataSource = dt1;
}
else
{
MessageBox.Show("no record found");
GridView2.DataSource = null;
}
}
private void DateSearch_Load(object sender, EventArgs e)
{
txt_startdate.Focus();
}
Best,
Sudheep.