Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get data in datagridview to display at run time?

Status
Not open for further replies.

pescadore

Technical User
Nov 3, 2009
8
US
I'm using Visual Basic 2008 in Windows 7. I've added a datasource to my project and dragged an element, a sort query, from Data Sources onto my form. It automatically created a DataViewGrid and placed this statement in my form load event:
Code:
Me.SortBillsTableAdapter.Fill(Me.DoBills_2009DataS et.sortBills)
The datagridview shows all the fields/columns. When I preview the data element, a sort query, from right clicking the element, selecting Preview Data, and click Preview in the Preview Data dialog box, the data appears. But the data does not appear when I run the app. The datagridview is empty. What am I missing to get the data to display in the grid at run time? I did notice that in the properties for the dataviewgrid the databindings property is empty. Is that right or am I supposed to do something there?
 
Did you bind your datasource to the gridview? For example:
GridView1.DataBind()
This binds the data from the datasource to the gridview.
Cathy
 
Thanks for your response, MzKitty. I guess I don't know how to bind the datasource. I assume that Gridview1 in your example is the name of the datagridview control on my form. Mine is named SortBillsDataGridView, so I would bind the control with SortBillsDataGridView.GetData(). That generates an error: "GetData is not a member of System.Windows.Forms.DataGridView". I have tried this line of code before my Fill statement, "Me.SortBillsBindingSource.DataSource = Me.SortBillsTableAdapter.GetData()", but the data still does not appear at run time.
 
I am using a gridview which replaces the datagridview in VS 2008. I don't use tableadapters. I have to customize my select for the parameters that the user enters and so I update my select for the datasource on the fly. But my datasource is in the properties for my gridview, and automatically fills my gridview. This is all the code I have to use to populate my gridview:

specified customer - specified order - specified license
SqlDataSource2.SelectCommand = "SELECT TicketNo, UniqueID, TicketDate, LocationID, CustomerID, OrderID, VehicleID FROM Tkhist1 WHERE (LocationID = ?) AND (CustomerID = ?) AND (TicketDate >= ?) AND (TicketDate <= ?) AND (VehicleID >= ?) AND (VehicleID <= ?) AND (OrderID = ?) AND (VOIDSTATUS = 'A')"

Check_For_Data()

End Sub
Private Sub Check_For_Data()
Dim numCols As Integer = GridView1.Columns.Count
Dim numRows As Integer = GridView1.Rows.Count
Dim strWrite As String

IntUniqueID = 0
IntTktNo = 0
strTruck = ""
Dim count As Integer
strWrite = "NO"
count = 0 'numRows - 1
Dim count2 As Integer
count2 = 0
Dim row As GridViewRow
Try
row = GridView1.Rows(count)

Catch ex As Exception
lblMsg.Text = "No data for your selections."
lblMsg.Visible = True
btnCheckAll.Visible = False
btnUnCheckAll.Visible = False
btnexporttext.Visible = False

End Try
End Sub
 
GridViews and DataGridViews are two completely different controls, for different purposes. The DataGridView is used in Windows Forms, and the GridView is used in ASP.Net web pages. .DataBind does not apply to the DataGridView.

In Windows Forms, you should simply need to set the .DataSource property of your DataGridView.
 
Thanks RiverGuy. My .DataSource property is set to the bindingsource. The bindingsource.DataSource property is set to the dataset and it's .DataMember property is set to the correct table/query. I did build the project and when I run the executable I get this error message: "The Microsoft.ACE.12.0 provider is not registered on this machine." If I continue in spite of the error, I get the empty grid.
 
_____________________________________________________________________________________
Solution:

That's it! Thanks Arjun Paudel for the link. Here's the solution as found on XNA Creator's Club Online. It's by Stephen Styrchak.


The following erorr:

The 'Microsoft .ACE.OELDB.12.0' provider is not registered on the local machine

suggests me to believe that you are compiling for 64bit

I dont have express edition but are following steps valid in 2008 express?


Arjun Paudel
_____________________________________________________________________________________

In VC# Express, this property is missing, but you can still create an x86 configuration if you know where to look.

It looks like a long list of steps, but once you know where these things are it's a lot easier. Anyone who only has VC# Express will probably find this useful. Once you know about Configuration Manager, it'll be much more intuitive the next time.

1.In VC# Express 2005, go to Tools -> Options.
2.In the bottom-left corner of the Options dialog, check the box that says, "Show all settings".
3.In the tree-view on the left hand side, select "Projects and Solutions".
4.In the options on the right, check the box that says, "Show advanced build configuraions."
5.Click OK.
6.Go to Build -> Configuration Manager...
7.In the Platform column next to your project, click the combobox and select "<New...>".
8.In the "New platform" setting, choose "x86".
9.Click OK.
10.Click Close.
There, now you have an x86 configuration! Easy as pie! :)

I also recommend using Configuration Manager to delete the Any CPU platform. You really don't want that if you ever have depedencies on 32-bit native DLLs (even indirect dependencies).

Stephen Styrchak | XNA Game Studio Developer
_____________________________________________________________________________________
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top