同上.
解决方案 »
- VB中子窗体响应主窗体事件
- 把U盘用1覆盖是不是把U盘物理扇区内容全部写成1?
- 我想用windows media player做个小东东 但是我想自定义图象窗口 请大家帮忙啊
- 灌点水
- 假如你遇见这样的人……(郁闷散分)
- 高级问题(关于捕错)
- 当报表连接到数据库访问对象时出现的问题。
- 关于数据读取速度
- 用vb编,怎样用insert把一个数据库的表,插入到另一个数据库例
- 有关注册表的问题
- Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long为什么提示编译错误,是不是要
- VB运行例程
Sub CreateProcedure() Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim prm As ADODB.Parameter
Dim cat As New ADOX.Catalog ' Open the Connection
cnn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\" & _
"Office\Samples\Northwind.mdb;" ' Create the parameterized command (Jet specific)
Set cmd.ActiveConnection = cnn
cmd.CommandText = "PARAMETERS [CustId] Text;" & _
"Select * From Customers Where CustomerId = [CustId]" ' Open the Catalog
Set cat.ActiveConnection = cnn ' Create the new Procedure
cat.Procedures.Append "CustomerById", cmdEnd Sub开始事务,提交及会滚的例子
Public Sub BeginTransX() Dim cnn1 As ADODB.Connection
Dim rstTitles As ADODB.Recordset
Dim strCnn As String
Dim strTitle As String
Dim strMessage As String ' Open connection.
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Open strCnn ' Open Titles table.
Set rstTitles = New ADODB.Recordset
rstTitles.CursorType = adOpenDynamic
rstTitles.LockType = adLockPessimistic
rstTitles.Open "titles", cnn1, , , adCmdTable
rstTitles.MoveFirst
cnn1.BeginTrans ' Loop through recordset and ask user if she wants
' to change the type for a specified title.
Do Until rstTitles.EOF
If Trim(rstTitles!Type) = "psychology" Then
strTitle = rstTitles!Title
strMessage = "Title: " & strTitle & vbCr & _
"Change type to self help?" ' Change the title for the specified
' employee.
If MsgBox(strMessage, vbYesNo) = vbYes Then
rstTitles!Type = "self_help"
rstTitles.Update
End If
End If rstTitles.MoveNext
Loop ' Ask if the user wants to commit to all the
' changes made above.
If MsgBox("Save all changes?", vbYesNo) = vbYes Then
cnn1.CommitTrans
Else
cnn1.RollbackTrans
End If ' Print current data in recordset.
rstTitles.Requery
rstTitles.MoveFirst
Do While Not rstTitles.EOF
Debug.Print rstTitles!Title & " - " & rstTitles!Type
rstTitles.MoveNext
Loop ' Restore original data because this
' is a demonstration.
rstTitles.MoveFirst
Do Until rstTitles.EOF
If Trim(rstTitles!Type) = "self_help" Then
rstTitles!Type = "psychology"
rstTitles.Update
End If
rstTitles.MoveNext
Loop rstTitles.Close
cnn1.CloseEnd Sub
create proc Test(@id int ,@name varchar(20) output)
as
begin
select @name=customername from customers where customerid= @id
End
调用:
Dim cmd As ADODB.Command
Dim par1 As ADODB.Parameter
Dim par2 As ADODB.Parameter
Set cmd = New ADODB.Command
cmd.CommandText = "test"
cmd.CommandType = adCmdStoredProc
Set par1 = cmd.CreateParameter("a", adInteger, adParamInput, , 3)
cmd.Parameters.Append par1
Set par2 = cmd.CreateParameter("b", adVarChar, adParamOutput, 20)
cmd.Parameters.Append par2
Set cmd.ActiveConnection = cnDatabase
cmd.Execute
Debug.Print par2.Value
Set cmd = Nothing