Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by TexasAggie
Posted (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 by dotnetguy37
Posted

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!

  • 3 weeks later...
Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...