Data grid!
-
I've decided to use sql but I'm having problem with seeing my datagrid? Yet I set Property visible to true what could be the Problem Thanks.
you might not have called the databind() function of the datagrid.
-
you might not have called the databind() function of the datagrid.
-
Hi, Is it possible to insert data into datagrid with out getting the data from a database like sql or access. Thanks.
Grid can be bound to any Collection type. You can create a dummy datattable as following:- DataTable dt = new DataTable("Try"); dt.Columns.Add("column1"); dt.Rows.Add("one"); dt.Rows.Add("two"); dt.Rows.Add("three"); and now set the datasource to dt. Also you need to have atleast 1 row in datasource to get the grid displayed
Nana
-
I've decided to use sql but I'm having problem with seeing my datagrid? Yet I set Property visible to true what could be the Problem Thanks.
-
Grid can be bound to any Collection type. You can create a dummy datattable as following:- DataTable dt = new DataTable("Try"); dt.Columns.Add("column1"); dt.Rows.Add("one"); dt.Rows.Add("two"); dt.Rows.Add("three"); and now set the datasource to dt. Also you need to have atleast 1 row in datasource to get the grid displayed
Nana
Thank you, I was doing it like this. Hope private void Page_Load(object sender, System.EventArgs e) { if (! IsPostBack) { BindDataGrid(); } } private void BindDataGrid() { SqlCommand myCommand=new SqlCommand("SELECT * from Billing",con); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Open(); myCommand.ExecuteNonQuery(); dgbilling.DataSource=ds; dgbilling.DataBind(); con.Close(); } I had ever used this same code on another program and it worked properly. could you help me from there please Thanks.
-
Thank you, I was doing it like this. Hope private void Page_Load(object sender, System.EventArgs e) { if (! IsPostBack) { BindDataGrid(); } } private void BindDataGrid() { SqlCommand myCommand=new SqlCommand("SELECT * from Billing",con); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Open(); myCommand.ExecuteNonQuery(); dgbilling.DataSource=ds; dgbilling.DataBind(); con.Close(); } I had ever used this same code on another program and it worked properly. could you help me from there please Thanks.
use following code- SqlDataAdapter myAdapter=new SqlDataAdapter("SELECT * from Billing", con); con.Open(); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Close(); dgbilling.DataSource=ds; dgbilling.DataBind(); you dont need sqlcommand here at all. And one suggestion - read more about what is an adapter, dataset etc why is it used n all. I think one should know why is he/she using the object in the code.
Nana
-
use following code- SqlDataAdapter myAdapter=new SqlDataAdapter("SELECT * from Billing", con); con.Open(); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Close(); dgbilling.DataSource=ds; dgbilling.DataBind(); you dont need sqlcommand here at all. And one suggestion - read more about what is an adapter, dataset etc why is it used n all. I think one should know why is he/she using the object in the code.
Nana
-
Thank you, I was doing it like this. Hope private void Page_Load(object sender, System.EventArgs e) { if (! IsPostBack) { BindDataGrid(); } } private void BindDataGrid() { SqlCommand myCommand=new SqlCommand("SELECT * from Billing",con); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds=new DataSet(); myAdapter.Fill(ds); con.Open(); myCommand.ExecuteNonQuery(); dgbilling.DataSource=ds; dgbilling.DataBind(); con.Close(); } I had ever used this same code on another program and it worked properly. could you help me from there please Thanks.
when you use data adapters you do not need to open or close the connection, it does it by itselt. if the connection was already open before calling the fill command in data-adapert, it will leave it open and if it was close, it will open it get the data and then close it. the Fill() function will get the data; so, you do not need to call the ExecuteNonQuery() command again. you might try the following: private void BindDataGrid() { SqlCommand myCommand=new SqlCommand("SELECT * from Billing",con); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds=new DataSet(); myAdapter.Fill(ds); dgbilling.DataSource=ds; dgbilling.DataBind(); } this should give the required result.