Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql Procedure does not return value
Message
From
12/06/2006 04:48:23
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01128253
Message ID:
01128401
Views:
24
>Hi Please Analyse my following code.In this i am calling one stored procedure Grn_MAst_Add, it returns the new grn no but the value does not get return. Please check the .Net Code as well as Sql Stored procedure and let me know where i am missing something.
>
>
>Dim SqlCmd As New SqlCommand
>                Dim SqlTrn As SqlTransaction
>                Dim new_grn_no As Integer
>                SqlCmd.Connection = Me.ItemTableAdapter.Connection
>                SqlCmd.Connection.Close()
>                SqlCmd.Connection.Open()
>                SqlTrn = Me.ItemTableAdapter.Connection.BeginTransaction("Add_Grn")
>                SqlCmd.Transaction = SqlTrn
>                With SqlCmd
>                    .CommandText = "Grn_Mast_Add"
>                    .CommandType = CommandType.StoredProcedure
>                    .Parameters.Add("@edate", SqlDbType.DateTime).Value = Me.EDATE.Value
>                    .Parameters.Add("@our_ref_no", SqlDbType.VarChar, 50).Value = Me.Our_Ref_No.Text
>                    .Parameters.Add("@supplier", SqlDbType.VarChar, 50).Value = Me.Supplier.Text
>                    .Parameters.Add("@supplier_ref_no", SqlDbType.VarChar, 50).Value = Me.Supplier_Ref_No.Text
>                    .Parameters.Add("@notes", SqlDbType.VarChar, 50).Value = Me.Notes.Text
>                    .Parameters.Add("@created_by", SqlDbType.VarChar, 15).Value = ajes_stationery.LoginForm1.m_uname
>                    .Parameters.Add("@@Grn_No", SqlDbType.Int).Value = 0
>                End With
>                Try
>'following line where the value is returned, is having problem
>                    new_grn_no = SqlCmd.ExecuteScalar()
>                    Me.GRN_NO.Text = new_grn_no
>                    SqlCmd.CommandText = "Grn_Tran_Add"
>                    Dim i As Integer = 0
>                    SqlCmd.Parameters.Clear()
>                    With SqlCmd
>                        .Parameters.Add("@grn_no", SqlDbType.Int)
>                        .Parameters.Add("@edate", SqlDbType.DateTime)
>                        .Parameters.Add("@item_id", SqlDbType.Int)
>                        .Parameters.Add("@qty", SqlDbType.Float)
>                        .Parameters.Add("@item_rem", SqlDbType.VarChar, 100)
>                    End With
>                    For i = 0 To (Me.DataGridView1.Rows.Count - 1)
>                        With SqlCmd
>                            .Parameters("@grn_no").Value = new_grn_no
>                            .Parameters("@edate").Value = Me.EDATE.Value
>                            .Parameters("@item_id").Value = Val(Me.DataGridView1.Rows(i).Cells.Item(0).Value)
>                            .Parameters("@qty").Value = Val(Me.DataGridView1.Rows(i).Cells.Item(4).Value)
>                            .Parameters("@item_rem").Value = Val(Me.DataGridView1.Rows(i).Cells.Item(5).Value)
>                        End With
>                        SqlCmd.ExecuteNonQuery()
>                    Next
>                    SqlTrn.Commit()
>                    MsgBox("Record Added Successfully", MsgBoxStyle.Information, ajes_stationery.LoginForm1.co_name)
>                Catch e1 As Exception
>                    SqlTrn.Rollback()
>                    MsgBox(e1.Message, MsgBoxStyle.Exclamation, ajes_stationery.LoginForm1.co_name)
>                Finally
>                    SqlCmd.Connection.Close()
>                End Try
>
>
>
>
>and the stored procedure is as follows
>
>
>CREATE PROCEDURE Grn_Mast_Add
>	@edate datetime,
>	@our_ref_no varchar(50),
>	@supplier varchar(50),
>	@supplier_ref_no varchar(50),
>	@notes varchar(50),
>	@created_by varchar(15),
>	@@Grn_No  integer output
>
>AS
>	
>	set @@grn_no = (select isnull(max(grn_no),0)  from grn_mast)
>	set @@grn_no = @@grn_no + 1
>
>	insert into grn_mast(grn_no,edate,our_ref_no,supplier,supplier_ref_no,notes,created_by)
>		values (@@grn_no,@edate,@our_ref_no,@supplier,@supplier_ref_no,@notes,@created_by)
>	print @@grn_no
>
>	return @@grn_no
>GO
>
>
>
Riyaz,
Output parameters are not the same thing as return values. Check Re: VFP/ADO/SQL stored procedure syntax Thread #1056781 Message #1057068
Code there is with VFP and ADO but would show you the difference.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform