Returning Max with a stored procedure
I have read and retried rebuilding the below in many ways but to keep it
clear I will show my last attempt.
Aim - To get the Max value of column "UniqueID"
The column field 'uniqueID' is set as a bigint
I assume the error is in the line with addwithvalue in as I get "int" as
the return value
If I run the query SELECT MAX(UniqueID) FROM tblResults in SQL it works
Code
Dim connection5 As SqlConnection
Dim command5 As New SqlCommand
Dim ds5 As New DataSet
Dim ConnectionString5 As String =
System.Configuration.ConfigurationManager.ConnectionStrings("mySQLConnectionString").ToString()
connection5 = New SqlConnection(ConnectionString5)
connection5.Open()
command5.Connection = connection5
command5.Parameters.Clear()
command5.CommandText = "spUniqueUserID"
command5.Parameters.AddWithValue("@UniqueID", "")
command5.Parameters("@UniqueID").Direction =
ParameterDirection.Output
Session.Item("UniqueID") = command5.Parameters("@UniqueID").Value
connection5.Close()
Dim vShow As String
vShow = ""
vShow = Session.Item("UniqueID").ToString
SP
USE [DB]
GO
/****** Object: StoredProcedure [dbo].[spUniqueUserID] Script Date:
09/10/2013 08:51:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spUniqueUserID]
@UniqueID bigint OUTPUT
AS
BEGIN
select @UniqueID = (SELECT MAX(UniqueID) FROM tblResults )
Return @UniqueID
END
No comments:
Post a Comment