Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rs.open cmd.execute cn.execute Questions

Status
Not open for further replies.

bassguy

Programmer
Jun 21, 2001
336
US
Hello all,

I am currently trying to write some standards for coding for my department (...I am the department) and
I have an interesting question for discussion.

When I am connecting to a Database i have found there are several methods that can be used. here are a few of the scripts:


cnn="driver={SQL Server};server=rgreennt;uid=sa;pwd=;database=pubs"
Set rs=server.createobject("adodb.recordset")
ssql="Select * from Author"
rs.open ssql,cnn

This gives me a recordset to display.

Also there is:


Set cnn = New ADODB.Connection
cnn.ConnectionString = "driver={SQL server};server=rgreennt;uid=sa;pwd=;database=pubs"
cnn.Open
Set rs =cnn.Execute ("Select * from Author")


This also gives me a recordset to display
Yet a third example:



Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim fldloop As ADODB.Field
Dim param1 As Parameter, param2 As Parameter, param3 As Parameter
Dim provStr As String
Dim royalty As Variant


cn.Provider = "sqloledb"
provStr "Server=MyServer;Database=pubs;Trusted_Connection=yes"
cn.Open provStr
Set cmd.ActiveConnection = cn
cmd.CommandText = "myProc"
cmd.CommandType = adCmdStoredProc

Set param1 = cmd.CreateParameter("Return", adInteger, adParamReturnValue)
cmd.Parameters.Append param1

Set param2 = cmd.CreateParameter("Output", adInteger, adParamOutput)
cmd.Parameters.Append param2

Set param3 = cmd.CreateParameter("Input", adInteger, adParamInput)
cmd.Parameters.Append param3
royalty = Trim(InputBox("Enter royalty:"))
param3.Value = royalty
Set rs = cmd.Execute



Now with the exception of the paramaters in the 3rd instance, it appears I can get a recordset by any of the following if the prepwork is correct.

rs.open
cnn.execute
cmd.Execute


What are the pros and cons?

thanks for the time

Bassguy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top