p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 6th, 2008, 11:38 AM
Registered User
 
Join Date: Apr 2008
Location: , , Australia.
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?
:(

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old April 6th, 2008, 12:00 PM
planoie's Avatar
Friend of Wrox
Points: 16,368, Level: 55
Points: 16,368, Level: 55 Points: 16,368, Level: 55 Points: 16,368, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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

-Peter
peterlanoie.blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old April 7th, 2008, 09:30 AM
Registered User
 
Join Date: Apr 2008
Location: , , Australia.
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"


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old April 7th, 2008, 01:00 PM
planoie's Avatar
Friend of Wrox
Points: 16,368, Level: 55
Points: 16,368, Level: 55 Points: 16,368, Level: 55 Points: 16,368, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old April 8th, 2008, 11:27 AM
Registered User
 
Join Date: Apr 2008
Location: , , Australia.
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old April 8th, 2008, 03:42 PM
planoie's Avatar
Friend of Wrox
Points: 16,368, Level: 55
Points: 16,368, Level: 55 Points: 16,368, Level: 55 Points: 16,368, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 08:42 PM
Crystal Report, Stored Procedure, Dataset clioz Crystal Reports 0 July 19th, 2006 07: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 03:40 AM
DataSet empty...help kevin777 ASP.NET 1.1 4 June 24th, 2004 12:21 AM



All times are GMT -4. The time now is 11:40 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc