0

I am trying to get a result back from a stored procedure. I found this thread and modify it slightly to my need.

Here is my MYSQL Stored Procedure code :

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;

Here is my VB6 code :

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

The part "cmd.Parameters.Append cmd.CreateParameter("result", adInteger, adParamOutput)" is deliberately commented out as it will give error when it is active.

When the command button is clicked, it doesn't give out any error. But it doesn't give out any correct output too. This line "Debug.Print "result is: " & rs.Fields(0)" resulting as "?" (yes, it prints out a question mark)

Please help. Thanks.

padjee
  • 125
  • 2
  • 12
  • Doesn't make much sense to me. Trying to figure out what you're trying to look at. To start with you're defining output parameter as `result`, but it's named as `res` in your function. Your command doesn't return a recordset yet you're assigning it to a recordset. You should probably set `CommandType = adCmdStoredProc` and then pull the return value from `cmd.Parameters("res")` – dbmitch Jun 09 '18 at 15:21
  • Okey.i will try it on monday. – padjee Jun 09 '18 at 15:37

0 Answers0