for every record it shows the same values? [Resolved]

Posted by Sudheep.grandhe under C# on 12/15/2011 | Points: 10 | Views : 1156 | Status : [Member] | Replies : 1
Hi,

namespace marsweb.imageimpacts
{
public partial class DateSearch : Form
{
int id1=3;// because i am place here ' 3' for this reason it shows that record for every value.and i check in the server for every individual value it shows the record

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=Sudheeptest;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=Sudheeptest;integrated security=true");
SqlCommand cmd1 = new SqlCommand("select particulars,orderno,quantity,perprice,amount from tbl_report1 where invoiceid=@id1", con1);//here is the problem
cmd1.Parameters.AddWithValue("@id1",id1 );
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;
}


}





}
}

Best,
Sudheep.



Responses

Posted by: Sksingh on: 12/15/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,

try below code for your second grid binding

SqlConnection con1 = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true"); 

SqlCommand cmd1 = new SqlCommand("select t1.particulars,t1.orderno,t1.quantity,t1.perprice,t1.amount from tbl_report1 t1
join tbl_report2 t2
on t1.invoiceid = t2.invoiceno
where t2.invoicedate between @startdate and @enddate", con1);
cmd1.Parameters.AddWithValue("@startdate", Convert.ToDateTime(txt_startdate.Text));
cmd1.Parameters.AddWithValue("@enddate", Convert.ToDateTime(txt_enddate.Text));


Regards,
Sunil

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

Login to post response