Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2008, 10:38 AM
Registered User
 
Join Date: Apr 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
:(

 
Old April 6th, 2008, 11:00 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Could you post some of the relevant code so we might see what you are doing?

-Peter
peterlanoie.blog
 
Old April 7th, 2008, 08:30 AM
Registered User
 
Join Date: Apr 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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"


 
Old April 7th, 2008, 12:00 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
 
Old April 8th, 2008, 10:27 AM
Registered User
 
Join Date: Apr 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
 
Old April 8th, 2008, 02:42 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset & Stored Procedure Problem clioz BOOK: Professional Crystal Reports for VS.NET 0 July 21st, 2006 07:42 PM
Crystal Report, Stored Procedure, Dataset clioz Crystal Reports 0 July 19th, 2006 06:28 PM
Return DataSet / DataTable from Stored Procedure ashu_from_india ADO.NET 3 March 20th, 2005 05:39 AM
How to fill stored procedure in dataset. jayaraj ADO.NET 4 August 2nd, 2004 02:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.