it shows the same data in gridview?

Posted by Sudheep.grandhe under C# on 11/17/2011 | Points: 10 | Views : 893 | Status : [Member] | Replies : 2
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.



Responses

Posted by: perfectchourasia-9163 on: 11/17/2011 [Member] Starter | Points: 25

Up
0
Down
first of all please

<asp:GridView ID="gridsub" runat="server" AutoGenerateColumns="False" ShowFooter="True" OnRowEditing="gridsub_RowEditing" OnRowCancelingEdit="gridsub_RowCancelingEdit" OnRowDataBound="gridsub_RowDataBound" OnRowUpdating="gridsub_RowUpdating" OnRowCommand="gridsub_RowCommand">


i have given sample of code please use AutoGenerateColumns="False"

for http://sandeep-chourasia.blogspot.com/2011/09/editable-gridview.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

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

Posted by: Sudheep.grandhe on: 11/17/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

please i am developing windows applications not web applications.


Best,
Sudheep.

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

Login to post response