PC Review


Reply
Thread Tools Rate Thread

Access queryDef as stored procedure

 
 
=?Utf-8?B?am9uZWZlcg==?=
Guest
Posts: n/a
 
      3rd Jan 2006
in the 'Access Cookbook' by Getz, Litwin and Baron, it shows how to get a
qryAlternativeAlbums query as an OleDbDataReader:

'Construct an OleDbCommand to execute the query
Dim AltRock as OleDbCommand = _
New OleDbCommand("qryAlternativeAlbums", cnx)

'Odd as it may seem, you need to set the CommandType
'to CommandType.StoredProcedure.
cmdAltRock.CommandType = CommandType.StoredProcedure

'Run the query and place the rows in an OledbDataReader.
Dim drAltRock as OleDbDataReader
drAltRock = cmdAltRock.ExecuteReader

'Bind the OleDbDataReader to the DataGrid
dgrAltRock.DataSource = drAltRock
dgrAltRock.DataBind()


As an Access developer, this was exciting news, as I thought I presently had
no way to use joins to Union queries, etc...

Anyhow, I was wondering if I can use the DataAdapter in the same fashion?
Please help me get any kinks out if this is possible.
And if not, how can I parameterize a DataReader - is this possible?


 
Reply With Quote
 
 
 
 
Mary Chipman [MSFT]
Guest
Posts: n/a
 
      3rd Jan 2006
Access SQL has always supported UNION and UNION ALL queries. You can
save them and execute them using the code you posted. There's no point
in using a DataAdapter with a UNION query because it is not
updateable. You can supply parameter values to your command object in
the usual way -- see the OleDbParameter topic in Help for more
information.

--Mary

On Tue, 3 Jan 2006 11:07:03 -0800, "jonefer"
<(E-Mail Removed)> wrote:

>in the 'Access Cookbook' by Getz, Litwin and Baron, it shows how to get a
>qryAlternativeAlbums query as an OleDbDataReader:
>
>'Construct an OleDbCommand to execute the query
>Dim AltRock as OleDbCommand = _
>New OleDbCommand("qryAlternativeAlbums", cnx)
>
>'Odd as it may seem, you need to set the CommandType
>'to CommandType.StoredProcedure.
>cmdAltRock.CommandType = CommandType.StoredProcedure
>
>'Run the query and place the rows in an OledbDataReader.
>Dim drAltRock as OleDbDataReader
>drAltRock = cmdAltRock.ExecuteReader
>
>'Bind the OleDbDataReader to the DataGrid
>dgrAltRock.DataSource = drAltRock
>dgrAltRock.DataBind()
>
>
>As an Access developer, this was exciting news, as I thought I presently had
>no way to use joins to Union queries, etc...
>
>Anyhow, I was wondering if I can use the DataAdapter in the same fashion?
>Please help me get any kinks out if this is possible.
>And if not, how can I parameterize a DataReader - is this possible?
>

 
Reply With Quote
 
Robbe Morris [C# MVP]
Guest
Posts: n/a
 
      3rd Jan 2006
I'm a little confused by your question. That said, this
ADO.NET code generator will write the object oriented
data access layers needed to call all of your stored
queries/database statements in Microsoft Access.

It may help you...

http://www.eggheadcafe.com/articles/..._generator.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp





"jonefer" <(E-Mail Removed)> wrote in message
news:9B7663CC-EB1E-40A6-AB81-(E-Mail Removed)...
> in the 'Access Cookbook' by Getz, Litwin and Baron, it shows how to get a
> qryAlternativeAlbums query as an OleDbDataReader:
>
> 'Construct an OleDbCommand to execute the query
> Dim AltRock as OleDbCommand = _
> New OleDbCommand("qryAlternativeAlbums", cnx)
>
> 'Odd as it may seem, you need to set the CommandType
> 'to CommandType.StoredProcedure.
> cmdAltRock.CommandType = CommandType.StoredProcedure
>
> 'Run the query and place the rows in an OledbDataReader.
> Dim drAltRock as OleDbDataReader
> drAltRock = cmdAltRock.ExecuteReader
>
> 'Bind the OleDbDataReader to the DataGrid
> dgrAltRock.DataSource = drAltRock
> dgrAltRock.DataBind()
>
>
> As an Access developer, this was exciting news, as I thought I presently
> had
> no way to use joins to Union queries, etc...
>
> Anyhow, I was wondering if I can use the DataAdapter in the same fashion?
> Please help me get any kinks out if this is possible.
> And if not, how can I parameterize a DataReader - is this possible?
>
>



 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      4th Jan 2006
On Tue, 3 Jan 2006 11:07:03 -0800, "jonefer" <(E-Mail Removed)> wrote:

¤ in the 'Access Cookbook' by Getz, Litwin and Baron, it shows how to get a
¤ qryAlternativeAlbums query as an OleDbDataReader:
¤
¤ 'Construct an OleDbCommand to execute the query
¤ Dim AltRock as OleDbCommand = _
¤ New OleDbCommand("qryAlternativeAlbums", cnx)
¤
¤ 'Odd as it may seem, you need to set the CommandType
¤ 'to CommandType.StoredProcedure.
¤ cmdAltRock.CommandType = CommandType.StoredProcedure
¤
¤ 'Run the query and place the rows in an OledbDataReader.
¤ Dim drAltRock as OleDbDataReader
¤ drAltRock = cmdAltRock.ExecuteReader
¤
¤ 'Bind the OleDbDataReader to the DataGrid
¤ dgrAltRock.DataSource = drAltRock
¤ dgrAltRock.DataBind()
¤
¤
¤ As an Access developer, this was exciting news, as I thought I presently had
¤ no way to use joins to Union queries, etc...
¤
¤ Anyhow, I was wondering if I can use the DataAdapter in the same fashion?
¤ Please help me get any kinks out if this is possible.
¤ And if not, how can I parameterize a DataReader - is this possible?
¤

Yes, you can run an Access QueryDef using a DataAdapter:

Dim AccessConn As System.Data.OleDb.OleDbConnection
Dim AccessCommand As System.Data.OleDb.OleDbCommand
Dim AccessReader As System.Data.OleDb.OleDbDataReader
Dim ConnectionString As String

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:System database=C:\Winnt\System32\System.MDW;" & _
"User ID=Admin;" & _
"Password="

AccessConn = New System.Data.OleDb.OleDbConnection(ConnectionString)

AccessConn.Open()
AccessCommand = New System.Data.OleDb.OleDbCommand("ValidateUser", AccessConn)
AccessCommand.CommandType = CommandType.StoredProcedure
Console.WriteLine(AccessCommand.CommandText)
AccessCommand.Parameters.Add("@pUserID", CType(System.Data.OleDb.OleDbType.VarWChar,
System.Data.OleDb.OleDbType), 15).Value = "username"
AccessCommand.Parameters.Add("@pPassword", CType(System.Data.OleDb.OleDbType.VarWChar,
System.Data.OleDb.OleDbType), 15).Value = "password"

Dim da As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
With da
.SelectCommand = AccessCommand
End With

Dim ds As New DataSet
da.Fill(ds)

The following uses the DataReader w/the above Command:

AccessReader = AccessCommand.ExecuteReader


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure in Access hoachen Microsoft Access 4 18th Oct 2009 11:54 AM
Stored SQL Procedure from Access? =?Utf-8?B?RGVubmlz?= Microsoft Access Queries 1 16th Apr 2007 07:24 PM
ht use MS Access like a stored procedure? Rigid Kitten Microsoft Dot NET 2 22nd Feb 2005 02:38 PM
stored procedure from Access? Josh Grameson Microsoft Access 1 28th Nov 2004 05:20 PM
MS Access Stored Procedure Jim Heavey Microsoft ADO .NET 1 5th Feb 2004 03:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:46 PM.