我已经阅读并尝试以多种方式重建以下内容,但为了清楚起见,我将展示我的最后一次尝试。
目标 - 获取列“UniqueID”的最大值
列字段 'uniqueID' 设置为 bigint
我假设错误与 addwithvalue in 一致,因为我得到“int”作为返回值
如果我运行查询SELECT MAX(UniqueID) FROM tblResults in SQL
它可以工作
代码
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", SqlDbType.BigInt)
command5.Parameters("@UniqueID").Direction = ParameterDirection.Output
command5.CommandType = CommandType.StoredProcedure
command5.ExecuteNonQuery()
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