473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DataSet empty when populating from a stored procedure in Access

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 query in Access displays two rows of data.

Any ideas as to why this is happening?
Apr 6 '08 #1
6 1725
balabaster
797 Expert 512MB
Not without your code mate
Apr 6 '08 #2
Sorry.

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"
Apr 7 '08 #3
balabaster
797 Expert 512MB
Bah, I don't have DataGridView in 2.0...does it have a DataBind method? If it does add that after the last line of the code you posted and you should be there...
Apr 7 '08 #4
No, there is no DataBind method.
Binding the data is done through the following based on what I've found so far.

DataMember - Gets or sets the name of the list or table in the data source for which the DataGridView is displaying data.
DataSource - Gets or sets the data source that the DataGridView is displaying data for.
Apr 7 '08 #5
Since the column headings were shown I decided to test the procedure by substituting the stored procedure for a table.

When I use a DataTable instead of a DataSet the correct information is obtained from the Access database and displays fine.

The code I used is:

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?
Apr 8 '08 #6
balabaster
797 Expert 512MB
That would make sense I suppose what with a dataset being potentially multiple tables, relationships the works and a DataGridView really is only used for single tables...
Apr 8 '08 #7

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

Similar topics

1
by: MicroMoth | last post by:
I know that this is probably a simple question, but I can't seem to find out how to populate the form fields I have with the results from my stored procedure, which I have stored in a datase. I...
12
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they...
9
by: Nikolay Petrov | last post by:
How to fill DataSet from stored procedure?
1
by: Sheldon Penner | last post by:
I have been trying to build a web form using the SQL Data Adapter Configuration Wizard to create a dataset based on a parameterized stored procedure. I find that if I select "Use existing stored...
5
by: John | last post by:
Hi all, I'm sorry I'm reposting this but the original was urgent and I do need closure on this. I'm calling a stored proc which does 4 "selects" and then I populate a dataset looping through...
3
by: vickilynnpgc | last post by:
I have a tsql stored procedure I want to drag from server explorer onto an xsd file. I get the error ' xml schema could not be interpreted'. The stored procedure does a select from a udf, that's...
5
by: John | last post by:
Hi, I am developing a windows app using C# 2005. This app uses SQL Server or Oracle database depending on the what the user is using. Can I create one typed dataset and use it for SQL Server and...
7
by: David | last post by:
Hi, using C# asp.net 1.1 I am having a problem. If I use the code below, but have null passed as the PostingGuid, then by the time I get to fill the dataset, I have "an object is not set to...
11
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.