TexasAggie Posted May 10, 2012 Posted May 10, 2012 (edited) I am using the same query to plot data and to show it in a datagridview. I get data to plot, but it won't display on my datagrid view. The DGV just stays grey. I've looked at a bunch of examples only and I can't find the problem. Any ideas? dgvSummary.AutoGenerateColumns = True sqlCmd = New SqlCommand(sql, conn) sqlAdp = New SqlDataAdapter(sqlCmd) sqlDs = New DataSet sqlAdp.Fill(sqlDs, "Development") dgvSummary.DataSource = sqlDs Edited May 10, 2012 by TexasAggie Quote
dotnetguy37 Posted May 10, 2012 Posted May 10, 2012 (edited) Usually besides a setting .datasource most code like this also involves setting a data member. At run time, use the SetDataBinding method to set the DataSource and DataMember properties. The following data sources are valid: A DataTable A DataView A DataSet A DataViewManager Any component that implements the IListSource interface Any component that implements the IList interface If the DataSource reference contains more than one table, you must set the DataMember property a string that specifies the table to bind to. For example, if the DataSource is a DataSet or DataViewManager that contains three tables named Customers, Orders, and OrderDetails, you must specify the table to bind to. There some code of this MSDN page that shows how to do this. I believe the DataGridView control also has a Refresh method, which this MSDN page says: Forces the control to invalidate its client area and immediately redraw itself (So you might try also adding a "dgvSummary.Refresh") If none of these help there could be other issues. Here's some links: DataGridView Not Showing Data My DataGridView won't display data Edited May 10, 2012 by dotnetguy37 Quote
TexasAggie Posted May 11, 2012 Author Posted May 11, 2012 Following your link (which was for an older control called dataview) I found this link: http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx And generated this code which works: sqlAdp = New SqlDataAdapter(sql, conn) Dim commandBuilder As New SqlCommandBuilder(sqlAdp) ' Populate a new data table and bind it to the BindingSource. Dim table As New DataTable() table.Locale = System.Globalization.CultureInfo.InvariantCulture sqlAdp.Fill(table) dgvSummary.DataSource = table I didn't have a table in my old code. Thanks! Quote
Dharmendra Rai Posted May 28, 2012 Posted May 28, 2012 Following your link (which was for an older control called dataview) I found this link: http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx And generated this code which works: sqlAdp = New SqlDataAdapter(sql, conn) Dim commandBuilder As New SqlCommandBuilder(sqlAdp) ' Populate a new data table and bind it to the BindingSource. Dim table As New DataTable() table.Locale = System.Globalization.CultureInfo.InvariantCulture sqlAdp.Fill(table) dgvSummary.DataSource = table I didn't have a table in my old code. Thanks! If ur using Procedure then use this..... SqlDataAdapter da; da = new SqlDataAdapter("sp_DGFillBuyerMaster", OpenConnection()); da.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); da.Fill(ds, "PartyMaster"); return ds; After Then Call this Method on Code... gridview.DataSource = ClassName.Method().Tables[0].DefaultView; this with run Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.