Stored Procedures with Access and .NET?

ismail7

New Member
I just got VisualStudio.Net and although I'm completely confused as to how to use it (or anything .NET for that matter), I did notice something unusual that seems kind of usefull... When I create a database connection to an Access 2000 database, VisualStudio.NET shows some of the Queries as either Stored Procedures or Views which I thought were not possible in Access (at least not without a lot of work.) <BR><BR>At the moment, I can't figure out how to do much in VS.NET, so I can't really test to see if these Queries are being treated as real Stored Procedures, or if this is just a glitch in VS.NET. That, and I'm not sure why some of my queries are showing up as Views while others are showing up as Stored Procedures.<BR><BR>Has anyone tried using Access queries as Stored Procedures? Does it work?Hi,<BR><BR>If you have a query stored in you access database then it becomes the equivalent of a stored procedure (in that it is a query stored in the database and gets compiled).<BR><BR>You refer to it by name and can call it with parameters a la SQL stored procedures:<BR><BR><BR>Dim objConnection As OledbConnection<BR>Dim objCmd As OledbCommand<BR>Dim strConnection As String<BR><BR>strConnection = "CONNECTION STRING HERE"<BR><BR>'Create and open connection object<BR>objConnection = New OledbConnection(strConnection)<BR>objConnection.Open()<BR><BR>'Create the command and set its properties<BR>objCmd = New OledbCommand()<BR>objCmd.Connection = objConnection<BR>objCmd.CommandText = "[NAME OF STORED PROCEDURE/QUERY]"<BR>objCmd.CommandType = CommandType.StoredProcedure<BR><BR>YOURDATAGRID.DataSource = objCmd.ExecuteReader(CommandBehaviour.CloseConnect ion)<BR><BR>YOURDATAGRID.DataBind()<BR><BR>Woo Hoo<BR><BR>Good old big red wrox books<BR><BR>Dan<BR><BR><BR><BR>
 
Back
Top