473,799 Members | 3,866 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating DataGridView with Access 2007 Query

10 New Member
Hello

I'm trying to populate a DataGridView with a stored procedure using VB.NET.
The query I need to use is within a Access 2007 datadase. When I run it in Access it is showing data but the DataGridView displays nothing.

The code I'm using to populate the DataGridView is:

------------------------------------------------------------------------------
'Create connection object.
CConnection = New CDatabaseConnec tion
With CConnection
.NewMSAccessCon nection(strFile Path)
.OpenDBConnecti on()
End With

'Initialize a new instance of the OleDbCommand class.
objCommand = New OleDbCommand

'Set command object properties.
objCommand.Comm andText = "usp_AccessQuer y"
objCommand.Comm andType = CommandType.Sto redProcedure
objCommand.Conn ection = CConnection.obj Connection

'Initialize a new instance of the Adapter class.
objDataAdapter = New OleDbDataAdapte r

'Initialize a new instance of the DataSet class.
objDataSet = New DataSet

'Set the SelectCommand for the DataAdapter.
objDataAdapter. SelectCommand = objCommand

'Populate the DataSet.
objDataAdapter. Fill(objDataSet )

Me.DataGridView 1.DataSource = objDataSet
------------------------------------------------------------------------------

I tried to populate a DataGrid using the same code sequence and found I had to select the expand icon within the grid to show a list of all the query columns with headings, but no data was shown.

Any ideas as to why this is happening?
Since I'm going to be doing more of this type of programming, does anyone know of some good sites with tutorials for working with Access databases in VB.NET?

Thanks.
Mar 30 '08 #1
3 2921
balabaster
797 Recognized Expert Contributor
Try adding:


Me.DataGrid1.Da taBind()

after the line where you set the data source...
Mar 30 '08 #2
WestAussie
10 New Member
Try adding:


Me.DataGrid1.Da taBind()

after the line where you set the data source...
Thanks for your reply balabaster.

I tried your suggestion but the following error occurred.

'DataBind' is not a member of 'System.Windows .Forms.DataGrid View'.

Since I posted my original question I have experimented using a DataTable and linking that directly to the table in the database. When I used a DataGrid the correct information was displayed. When I went to use the DataTable with the DataGridView no table content displayed, not even column headings.

Rather frustrating since all the code examples appear to work in the books I'm using.

Also, I've added a BindingSource and BindingNavigato r to the form which I'm hoping to be able to set parameters at run time. So far I haven't been able to display the data in order to test these objects.

Any other ideas I could try?
Mar 30 '08 #3
ISATownsME
3 New Member
Hello, I was wondering if you would know how to reverse the process meaning populating Access 2007 from DataGridView
Oct 23 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
29663
by: tee | last post by:
Hi, How do i sort datagridview programmically, current i have the following code but i keep get the error saying "DataGridView control must be bound to an IBindingList object to be sorted.", What is IBindingList and how would i go about using it. Here are my code private void dataGridView1_ColumnHeaderMouseClick(object sender,
3
14374
by: Przemek M. Zawada | last post by:
Dear Group, I'm developing sample window form, using DataGridView control, which is filled with data through BindingSource, which is based on type of object, as follow: public sampleClass { public int itemNumber; public string itemName;
7
13453
by: Mike | last post by:
i have a small difficulties with BindingSource and dataGridView bind db has properly opened and bind doesn't works. Unfortunately I didn't find any good example how to connect MS Access with dataGridView and BindSource class. Maybe something like this: DataTable dtResult = new DataTable(); dtResult = GetData(); // this line returns a error GetData doesn't exists!
8
7435
by: Kyote | last post by:
On my form I have a datagridview that's bound to a table on my DB. When I run the app then click on a column header to sort, it sorts just fine. But my problem is a result of that sort. Even though the view has been sorted, it's underlying data isn't. After sorting I'm trying to get the datarow I just doubleclicked on. The problem is it's returning the pre sorted row. That is, the row that was there before I sorted the column. Dim...
0
1252
by: CSharpie1000 | last post by:
I am sorry for the broadness of this question, but I litterally can't get anywhere with this. I have a dataGridView that loads data from an Access 2007 Database. This works fine. I would like to, when I double click on a dataGridView row though, have a second form open with the information displayed in textboxes, etc. Not all of my data is in the dataGridView. From what I can gather, I would use the dataGridView RowEnter event for this,...
0
3251
JordanMartz
by: JordanMartz | last post by:
''' <summary> ''' Populates the DataGridView ''' </summary> Private Sub PopulateDataGridView() ' Set the column header names. userAccessGrid.ColumnCount = 5 userAccessGrid.RowsDefaultCellStyle.BackColor = Color.White userAccessGrid.RowHeadersVisible = True userAccessGrid.Name = "User Access Grid" userAccessGrid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised
12
13649
by: cj | last post by:
When viewing a datatable in a datagridview one of the columns in it is a "note" field which can be quite long. I would like to have the note field of the currently selected row of the datagrid display in a textbox below the datgridview. I currently have it fixed so if you click on a row the note field from that row is put in the textbox. I'd like this to be automatic as they move through rows. Also the note field is one of two fields...
6
1738
by: WestAussie | last post by:
Hello I'm using Visual Studio 2005 and Microsoft Access 2007 (database is saved in 2007 format). The code which I have been using to display data in a DataGridView from a stored procedure in Microsoft Access comes from 'Beginning Visual Basic 2005 Databases' (Wrox publication). From what I have found my code works but no records are displayed in the DataGridView. The column headings are visible but the acutal data is not. Running the...
0
1353
by: Ed Bitzer | last post by:
Appreciate some direction on populating an unbound DataGridView with an one dimensional array of date an appointments (a calendar) read from a coma delimited text file. My original approach was to populate after searching for today's date and then increment a week at a time by repopulating after a PageDown event and changing the start index. No problem with PgUp and PgDn but I find I find myself in the middle of a nightmare controlling...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.