1 Replies - 1089 Views - Last Post: 18 October 2012 - 09:54 PM Rate Topic: -----

#1 jaijune02  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-October 12

unable to fetch o/p parameter value from sql stored proc in vb 6

Posted 17 October 2012 - 11:53 PM

Vb 6.0 Code

Private Sub Command2_Click()
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset

cn.ConnectionString = "Provider=SQLOLEDB.1; Persist Security Info=False; Trusted_Connection=Yes; User ID=sa; Password=sa; Initial Catalog=dream; Data Source=sa"
cn.Open

cmd.ActiveConnection = cn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "proc_insstudent"


cmd.Parameters.Append cmd.CreateParameter("sid", adInteger, adParamInput, , Text1.Text)
cmd.Parameters.Append cmd.CreateParameter("sname", adVarChar, adParamInput, 10, Text2.Text)
cmd.Parameters.Append cmd.CreateParameter("status", adTinyInt, adParamInput, , Text3.Text)
cmd.Parameters.Append cmd.CreateParameter("m1", adVarChar, adParamInput, 20, Format(Text4.Text, ".00"))
cmd.Parameters.Append cmd.CreateParameter("flag", adInteger, adParamOutput, , 0)

Set rs = cmd.Execute

Msgbox cmd("flag")

End sub




Stored Procedure

create procedure [dbo].[proc_insstudent]
@sid int,
@sname varchar(10),
@status tinyint,
@m1 numeric(6,2),
@flag int OUTPUT
as
begin
insert into student values(@sid,@sname,@status,@m1)
set @flag=1
select @flag
end


Problem
the stored procedure is to insert value into student table and set the output parameter @flag=1,

once the procedure is executed from vb 6, @flag out parameter should return 1,but still am getting 0 only,
correct me where am going wrong,
thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: unable to fetch o/p parameter value from sql stored proc in vb 6

#2 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: unable to fetch o/p parameter value from sql stored proc in vb 6

Posted 18 October 2012 - 09:54 PM

click this link
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1