小弟半路出家看了个vb程序,结果在执行带参数的存储过程时报错,再就是想问如何取返回值;Dim str_sql As String
str_sql = "Exec Pro_DFJS '" & str_CSVfailed & "'," & NowPrice & "," & baojingxianzhi & ",'" & str_sunhaoft1 & "','" & str_bjinclude & "','" & str_gongyongft & "'"
Dim str_jsxx As String
Dim LastDb As New ADODB.Recordset
If Main_conn.State = 0 Then Main_conn.Open
With LastDb
.ActiveConnection = Main_conn
.Source = str_sql
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Execute str_sql
While Not .EOF
'如果是0计算失败
If Len(.Fields("bz")) = "0" Then
fault = Trim(.Fields("falut"))
str_jsxx = Trim(.Fields("nr"))
MsgBox str_jsxx, vbInformation, Mytitle
Call faucolor
End If
'如果是1计算成功
If Len(.Fields("bz")) = "1" Then
str_jsxx = "电费计算成功!"
End If
.MoveNext
Wend
.Close
End With
str_sql = "Exec Pro_DFJS '" & str_CSVfailed & "'," & NowPrice & "," & baojingxianzhi & ",'" & str_sunhaoft1 & "','" & str_bjinclude & "','" & str_gongyongft & "'"
Dim str_jsxx As String
Dim LastDb As New ADODB.Recordset
If Main_conn.State = 0 Then Main_conn.Open
With LastDb
.ActiveConnection = Main_conn
.Source = str_sql
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Execute str_sql
While Not .EOF
'如果是0计算失败
If Len(.Fields("bz")) = "0" Then
fault = Trim(.Fields("falut"))
str_jsxx = Trim(.Fields("nr"))
MsgBox str_jsxx, vbInformation, Mytitle
Call faucolor
End If
'如果是1计算成功
If Len(.Fields("bz")) = "1" Then
str_jsxx = "电费计算成功!"
End If
.MoveNext
Wend
.Close
End With
获取以后是这样,
.Execute str_sql
改为
set lastDB=MAin_conn.execute(strSql)
' str_sql = "Exec Pro_DFJS @参数1='" & str_CSVfailed & "',@参数2=" & NowPrice ……
Dim str_jsxx As String
Dim LastDb As New ADODB.Recordset
If Main_conn.State = 0 Then Main_conn.Open
With LastDb
.ActiveConnection = Main_conn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open str_sql
While Not .EOF
'如果是0计算失败
If Len(.Fields("bz")) = "0" Then
fault = Trim(.Fields("falut"))
str_jsxx = Trim(.Fields("nr"))
MsgBox str_jsxx, vbInformation, Mytitle
Call faucolor
End If
'如果是1计算成功
If Len(.Fields("bz")) = "1" Then
str_jsxx = "电费计算成功!"
End If
.MoveNext
Wend
.Close
End With
Set LastDb = Nothing
Dim cmd As New ADODB.Command
Dim LastDb As New ADODB.Recordset'Build the Command object
With cmd
.ActiveConnection = Main_conn
.CommandText = "Pro_DFJS"
.CommandType = adCmdStoredProc
.Parameters.Refresh
.Parameters("@参数名1") = str_CSVfailed '参数名你自己替换成正确的'
.Parameters("@参数名2") = NowPrice '参数名你自己替换成正确的'
……
.Parameters("@参数名n") = str_gongyongft '参数名你自己替换成正确的'
End With'Create the Recordset
Set LastDb = cmd.Execute
MsgBox rs.Fields("字段名1") '字段名你自己替换成正确的'
rs.Close
Set rs = Nothing
Set cmd = Nothing