|
|
 |
| Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Studio 2005 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

April 6th, 2008, 11:38 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Location: , , Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Empty DataSet Populated By Stored Procedure
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'.
From what I have found my code works but no records are displayed in the DataGridView. The column headings are visible but the actual data is not. Running the query in Access displays two rows of data.
Any ideas as to why this is happening?
:(
|

April 6th, 2008, 12:00 PM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Could you post some of the relevant code so we might see what you are doing?
-Peter
peterlanoie.blog
|

April 7th, 2008, 09:30 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Location: , , Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Peter
Sorry, I should have included this originally.
objConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0 ;Data Source=C:\MyDatabase.accdb;Persist Security Info=False;")
'Initialize a new instance of the OleDbCommand class.
objCommand = New OleDbCommand
'Set command object properties.
objCommand.CommandText = "qryMyAccessQuery"
objCommand.CommandType = CommandType.StoredProcedure
objCommand.Connection = objConnection
'Initialize a new instance of the Adapter class.
objDataAdapter = New OleDbDataAdapter
'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, "DataSet")
Me.DataGridView.DataSource = objDataSet
Me.DataGridView.DataMember = "DataSet"
|

April 7th, 2008, 01:00 PM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Have you debugged this yet to see if objDataSet contains anything?
I'm not sure if you need to specify the DataMember in order to get the data to display. But I haven't done much windows forms apps so I can't say for sure.
-Peter
peterlanoie.blog
|

April 8th, 2008, 11:27 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Location: , , Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Peter
I tried to determine if there was any data in the DataSet but wasn't sure of the best way to do this. (What is the right way to check if a DataSet contains data?)
So I changed the Command object to reference a table using the following code and the data is displayed as it should be.
objConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0 ;Data Source=C:\MyDatabase.accdb;Persist Security Info=False;")
'Initialize a new instance of the OleDbCommand class.
objCommand = New OleDbCommand
'Set command object properties.
objCommand.CommandText = "tblMyAccessTable"
objCommand.CommandType = CommandType.TableDirect
objCommand.Connection = objConnection
'Initialize a new instance of the Adapter class.
objDataAdapter = New OleDbDataAdapter
'Initialize a new instance of the DataTable class.
dt = New DataTable
'Set the SelectCommand for the DataAdapter.
objDataAdapter.SelectCommand = objCommand
'Populate the DataTable.
objDataAdapter.Fill(dt)
Me.DataGridView.DataSource = dt
I must be missing a step in populating the data into a DataSet within my previous code. Any ideas as to what it might be?
|

April 8th, 2008, 03:42 PM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
The only difference I see is that you are querying a query versus a table. I haven't worked with Access in .NET so I can't provide you much help in that regard. However, I can't imagine they would be much different though.
-Peter
peterlanoie.blog
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |