Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Returning values from SQL Server
Message
De
03/08/2004 09:46:18
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
À
03/08/2004 09:36:30
Jim Rieck
Quicken Loans/Rock Financial/Title Sourc
Livonia, Michigan, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Divers
Thread ID:
00930321
Message ID:
00930326
Vues:
19
In SQL Server you designate one of the parameters passed in as OUTPUT. Then your sp returns the value as the output parameter:

The call: EXEC your_sp param, param1, param2 OUTPUT

In the stored proc....

your code...

RETURN @nValue

Then you query your param2 for the value returned from SQL Server.




>All,
>
> I have a stored procedure that I am calling from a webform. The stored procedure is updating a table called Task_header. The task_header table has a automatically incramenting field called taskhdr_id. I want the stored procedure to return the value of the taskhdr_id field to my webform when a record is inserted. How do I go about doing this? The code that I have is below.
>
>
>'Webform calling the stored procedure
>    Private Sub setInsertTaskHeaderParameters()
>        With Me.daTaskHeader.InsertCommand
>            Me.getMaxTaskNo()
>            .Parameters("@task_no").Value = txtTaskno.Text
>            .Parameters("@project_id").Value =  cboProjects.SelectedItem.Value
>            .Parameters("@lkup_id").Value = daStatus.SelectCommand.Parameters("@lkup_id").Value
>            .Parameters("@descrip").Value = Me.txtDescrip.Text
>            .Parameters("@start_date").Value = CType(Me.txtStartDate.Text, DateTime)
>            .Parameters("@status_id").Value = Me.cboStatus.SelectedItem.Value
>            .Parameters("@userid").Value = Session("username")
>        End With
>    End Sub
>
>'Stored Procedure
>ALTER PROCEDURE InsertTaskHeader
>(
>	@task_no int,
>	@project_id int,
>	@lkup_id int,
>	@descrip text,
>	@start_date datetime,
>	@status_id int,
>	@userid char(10)
>)
>AS
>INSERT INTO task_header(task_no, project_id, lkup_id, descrip, start_date, status_id, timestamp_created, userid_created)
>VALUES (@task_no, @project_id, @lkup_id, @descrip, @start_date, @status_id, getdate(), @userid)
>   RETURN
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform