CREATE PROC[EDURE] procedure_name[;number] [{@parameter data_type}[VARYING][=default][OUTPUT] ]],…n] [WITH{RECOMPILE|ENCRYPTION|RECOMPILE,ENCRYPTION}] [FOR REPLICATION] AS sql_statement[…n] |
Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Science_File;Data Source=Data_Server |
dim odbcstr as String, adocon As New ADODB.Connection odbcstr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Science_File;Data Source=Data_Server" adocon.Open odbcstr '连接到数据库 |
Dim ado as ADODC ado.ConnectionString = "Provider=SQLOLEDB.1;Password=" & User_Pwd & ";Persist Security Info=True;User ID=" & User_Name & ";Initial Catalog=" & Data_Name & ";Data Source=" & server_name |
Dim strS As String '定义一变量 Dim adoconn As New ADODB.Connection 'Connection 对象代表了打开与数据源的连接。 Dim adocomm As New ADODB.Command 'Command 对象定义了将对数据源执行的指定命令。 Dim ReturnValue As Integer '调用存储过程的返回值 adoconn.ConnectionString = Adodc1.ConnectionString 'Adodc1为窗体中的ADO控件,并已成功连接数据库 adoconn.Open Set adocomm.ActiveConnection = adoconn '指示指定的 Command对象当前所属的 Connection对象。 adocomm.CommandText = "doc_ProcName" '设置Command对象源。 adocomm.CommandType = adCmdStoredProc '通知提供者CommandText属性有什么,它可能包括Command对象的源类型。设置这个属性优化了该命令的执行。 adocomm.Parameters(1) = "1" adocomm.Parameters(2) = "OutputParameters" 'OutputParameters可以为任意的字符串或数字 adocomm.Execute ReturnValue = adocomm.Parameters(0) '存储过程的返回值,返回0则成功执行。 strS = adocomm.Parameters(2) '把存储过程的输出参数的值赋给变量strS |
Set parameter = command.CreateParameter (Name, Type, Direction, Size, Value) |
Dim mRst As ADODB.Recordset 'Recordset 对象表示的是来自基本表或命令执行结果的记录全集。 Dim prm As ADODB.Parameter 'Parameter 对象代表参数或与基于参数化查询或存储过程的Command 对象相关联的参数。 adoconn.ConnectionString = Adodc1.ConnectionString adoconn.Open Set adocomm.ActiveConnection = adoconn adocomm.CommandText = "doc_ProcName" adocomm.CommandType = adCmdStoredProc Set prm = adocomm.CreateParameter("parameter1", adTinyInt, adParamInput, , "1") adocomm.Parameters.Append prm Set prm = adocomm.CreateParameter("parameter2", adInteger, adParamOutput) adocomm.Parameters.Append prm Set mRst = adocomm.Execute ReturnValue = adocomm.Parameters(0) |