If i enter the details in the form those details are not displayed in gridview?

Posted by Sudheep.grandhe under C# on 11/9/2011 | Points: 10 | Views : 941 | Status : [Member] | Replies : 4
Hi,

If i enter the details in the form those details are not displayed in gridview?.i am searching for the particular customer it wont display the customer name in gridview.in the gridview column1,column2 are shown instead of those i need to show invoicedate,ondate.how can i rectify these errors.

Best,
Sudheep.



Responses

Posted by: Blessyjees on: 11/9/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Provide the code that you are using to show data in the gridview.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

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

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

Up
0
Down
Hi,

Here is my code.please find it.

public void cmddisplaycustomer()
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select custid, custname from tbl_customer order by custname", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DataRow dr = dt.NewRow ();
dr[0] = "0";
dt.Rows.InsertAt(dr, 0);
//cmd.EndExecuteNonQuery();
//con.Close();
cmb_customername.DataSource = dt;
cmb_customername.ValueMember = "custid";
cmb_customername.DisplayMember = "custname";
//cmb_customername.Items.Insert(1, "-select one-");
cmb_customername.SelectedIndex = -1;
}


private void btn_search_Click(object sender, EventArgs e)
{
GridView2.Controls.Clear();
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),convert(varchar,InvoiceDate,105),AmountStatus,NetAmount,NetVat,TAmount from tbl_Report2 where compname=@compname", con);
con.Open();
cmd.Parameters.AddWithValue("@compname","cse global india pvt.ltd" );
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;

}
else
{
GridView1.Controls.Clear();
}
SqlConnection con2 = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd2 = new SqlCommand("select invoiceid from tbl_report1 where compname=@compname", con2);
cmd2.Parameters.AddWithValue("@compname", cmb_customername.SelectedItem.ToString());
SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
DataTable dt2 = new DataTable();
da2.Fill(dt2);
string invoiceid = dt2.ToString();

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=@InvoiceId", con1);
cmd1.Parameters.AddWithValue("@invoiceid", invoiceid);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
{
GridView2 .DataSource =dt1 ;
}



}

private void cmb_customername_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.Controls.Clear();
GridView2.Controls.Clear();
}

private void CustomerNameSearch_Load(object sender, EventArgs e)
{
cmddisplaycustomer();
GridView1.Controls.Clear();
GridView2.Controls.Clear();

}
}
}


Best,
Sudheep.

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

Posted by: Blessyjees on: 11/9/2011 [Member] Bronze | Points: 25

Up
0
Down
hi,

which grid shows the error. first grid you are usign to display customer information and second one is used to display order details, right? I couldn't understand what exact issue you specified after looked your code.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

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

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

Up
0
Down
Hi,

cmd.Parameters.AddWithValue("@compname","cse global india pvt.ltd" ); if i am specity the company name it shows that particular company name only .but others it wont display and in the gridview columns it displayed as a column1,column2 how can i change those

Best,
Sudheep.

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

Login to post response