473,757 Members | 5,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating and using Stored Procedures and Views in Jet

Perhaps many of you MS Access fanatics already know this, but it seems
that stored procedures and views are possible in Jet. I thought I
would leave this message just in case it would help anyone.

I discovered this the other day while doing some experiments with ADO
and ADO.NET. Basically, I wanted to run a stored MS Access query with
parameters using the syntax

Execute MyProcedure @Param1, @Param2...

I knew that I could run a stored Access query by creating ADODB
parameters, assigning values and executing as if I were running a
stored procedure. However, the above Execute syntax above also worked
perfectly to my surprise.

I later ran the code below from a Module in a simple Access database
with one table called Ranges with two columns (Range_ID integer,
Range_No varchar(50)). I expected to see the procedure prTest appear
in my list of queries, but it didn't--however it did appear in my
msysObjects table as type 5, which I think is for queries. I was able
to create, execute and drop the procedure as if I were working in SQL
Server.

I also tried creating a view, and did so with success. I was able to
create a ADO recordset by selecting from the view, which worked
perfectly as shown in the code below. Just like the procedure, the
view didn't show up in my list of stored queries, but it did appear in
msysobjects as type 5.

For me, this simply means that I can use ADO/ADO.NET to interact with
Jet databases in very much the same way that I do with SQL Server
databases.

I'm almost tempted to see if I can create a user-defined function in
Jet, but I'll save that for later.

Bill E.
Hollywood, FL

_______________ _______________ _____
Sub TestProcedure()
Dim strSQL As String
Dim objConn As ADODB.Connectio n
Dim rst As ADODB.Recordset

strSQL = "CREATE PROCEDURE prTest ([@intRange_ID] integer) AS
SELECT Range_No FROM Ranges WHERE Range_ID=[@intRange_ID]"

Set objConn = CurrentProject. Connection

'Create a procedure
objConn.Execute strSQL

'Run the procedure
Set rst = New ADODB.Recordset
strSQL = "EXECUTE prTest 1"

With rst
..ActiveConnect ion = objConn
..CursorType = adOpenStatic
..Open strSQL
Debug.Print .Fields("Range_ No")
..Close
End With

Set rst = Nothing

'Drop the procedure
strSQL = "DROP PROCEDURE prTest"
objConn.Execute strSQL

Set objConn = Nothing

End Sub

Sub TestView()
Dim strSQL As String
Dim objConn As ADODB.Connectio n
Dim rst As ADODB.Recordset

strSQL = "CREATE VIEW vwTest AS SELECT Range_No FROM Ranges"
Set objConn = CurrentProject. Connection

'Create a view
objConn.Execute strSQL

'Create a recordset based on the view
Set rst = New ADODB.Recordset
strSQL = "SELECT * FROM vwTest"

With rst
..ActiveConnect ion = objConn
..CursorType = adOpenStatic
..Open strSQL
Debug.Print .RecordCount
..Close
End With

Set rst = Nothing

'Drop the view
strSQL = "DROP VIEW vwTest"
objConn.Execute strSQL

Set objConn = Nothing

End Sub

Nov 13 '05 #1
0 2579

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6873
by: Dim St Thomas | last post by:
I am a developer working on a database client program. I am testing this program on a Windows XP machine (1.5 GHz AMD chip, 480 Mb RAM, 60 Gb disk) This machine has Oracle 9.2.0.1.0 and RedBrick database software installed. I am testing the software by creating small test databases. If I create an Oracle database using the Database Configuration Assistant, it takes forever just to create the database. If I choose to create a new database...
11
16299
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the equivalent to the SQL 'with' using TSQL? If there is not one, what is the TSQL solution to creating a temporary table that is associated with an SQL statement? Examples would be appreciated. Thank you!!
5
3498
by: gilles27 | last post by:
I've ready many of the posts on this and other newsgroups in which people describe working practices for source control of database scripts. We are looking to implement something similar in my current workplace. We have agreed that developers should not modify objects such as views or stored procedures directly, they should check the script out of VSS first, modify it, run it, and then check it back in. The problem we are having is...
10
5637
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures changed to be like:
1
2853
by: Matt Alanzo | last post by:
On another newsgroup an Access knowledgable party posted: >You should be able to connect an Access ADP to an existing SQLExpress >database running in SQLS 2000 compatibility mode. The only thing you >won't be able to do is access any of the design surfaces for SQLS >objects in the ADP. I checked with the Access team on this :-) > I appealed for clarification but without reply. Maybe somone on this newsgroup can provide insight.
28
72550
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
5
5063
by: BillCo | last post by:
I've encountered a problem while using ADO to save query objects. Union queries created normally (via the interface) appear in adox catelog.procedures rather than catelog.views. This is reasonably well documented and I can live with it. The below seems to be the only way to add queries to a database using ADO: Set cmd = New ADODB.Command cmd.CommandType = adCmdText
15
2884
by: Wes Groleau | last post by:
When I try to import from Access, the DTS wizard only allows me to import tables and queries. OK, I'm not surprised the "macros" and reports don't come over. But it executes each query, and created a _table_ to hold the results. The sensible thing would be that SELECT queries become views and the others become stored procedures. But I find no way controls I can select to do that.
2
6075
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still can't get it working. I have a query defined (view) and want the end user to put in a start date and end date to filter a report.
0
9487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.