我正在尝试从存储过程中获取结果。我找到了这条线,并根据我的需要稍加修改。
以下是我的mysql存储过程代码:
DROP PROCEDURE IF EXISTS `InsertList`;
CREATE DEFINER = `root`@`localhost` PROCEDURE `InsertList`(IN fName VARCHAR(20), IN fType VARCHAR(20), IN fFood varchar(20), OUT res INT)
BEGIN
insert into tblguest (firstname, confirm, food) values (fName, fType, fFood);
select count(firstname) from tblguest into res;
END;
下面是我的vb6代码:
Private Sub Command8_Click()
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim result As Integer
Set cmd = New ADODB.Command
cn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=localhost;" & " DATABASE=test;" & "UID=root;PWD=123;"
cn.Open
Set cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
cmd.CommandText = "Call InsertList(?,?,?,@fResult)"
cmd.Parameters.Append cmd.CreateParameter("fName", adVarChar, adParamInput, 10, Text4.Text)
cmd.Parameters.Append cmd.CreateParameter("fType", adVarChar, adParamInput, 10, Text5.Text)
cmd.Parameters.Append cmd.CreateParameter("fFood", adVarChar, adParamInput, 10, Text6.Text)
'cmd.Parameters.Append cmd.CreateParameter("result", adInteger, adParamOutput)
Set rs = cmd.Execute
Set rs = cn.Execute("select @fresult as theresult")
If Not rs.EOF Then
Debug.Print "result is: " & rs.Fields(0)
rs.MoveNext
End If
rs.Close
cn.Close
End Sub
“部分” cmd.Parameters.Append cmd.CreateParameter("result", adInteger, adParamOutput)
“是故意注解掉的,因为当它处于活动状态时会出现错误。
单击命令按钮时,不会显示任何错误。但是它也没有给出任何正确的输出。“这条线” Debug.Print "result is: " & rs.Fields(0)
“结果为”?“(是的,它打印出一个问号)
请帮忙。谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!