S
Steve
Hi All
Can someone help get the rowGUID value after an insert
I am using VB.net 2005 and SQL server Express 2005
The column GUID is an uniqueidentifier column with default value
(newsequentialid())
The following is my current function which is clumsy to say the least
I am sure there is a more elegant solution
Regards
Steve
----------------------------------------------------------------------------------------------------------
Public Function SaveParamDataGetGUID(ByVal mycmd As SqlCommand, ByVal
mytable As String) As Guid
Dim con As New SqlConnection, guid As Guid, sql As String = ""
Dim myint As Int16 = 0
Try
con.ConnectionString = connectionstring
con.Open()
mycmd.Connection = con
mycmd.ExecuteNonQuery()
sql = "select max(mykey) as maxkey from " & mytable
mycmd.CommandText = sql
myint = mycmd.ExecuteScalar
sql = "select guid from " & mytable & " where mykey = " & myint
mycmd.CommandText = sql
guid = mycmd.ExecuteScalar
Return guid
Catch ex As SqlException
mymsgbox(ex.Message)
Return Nothing
Finally
If Not IsNothing(mycmd) Then
mycmd.Dispose()
mycmd = Nothing
End If
If Not IsNothing(con) Then
con.Close()
con.Dispose()
con = Nothing
End If
End Try
End Function
---------------------------------------------------------------------------------------------------------------------------------------------------
Can someone help get the rowGUID value after an insert
I am using VB.net 2005 and SQL server Express 2005
The column GUID is an uniqueidentifier column with default value
(newsequentialid())
The following is my current function which is clumsy to say the least
I am sure there is a more elegant solution
Regards
Steve
----------------------------------------------------------------------------------------------------------
Public Function SaveParamDataGetGUID(ByVal mycmd As SqlCommand, ByVal
mytable As String) As Guid
Dim con As New SqlConnection, guid As Guid, sql As String = ""
Dim myint As Int16 = 0
Try
con.ConnectionString = connectionstring
con.Open()
mycmd.Connection = con
mycmd.ExecuteNonQuery()
sql = "select max(mykey) as maxkey from " & mytable
mycmd.CommandText = sql
myint = mycmd.ExecuteScalar
sql = "select guid from " & mytable & " where mykey = " & myint
mycmd.CommandText = sql
guid = mycmd.ExecuteScalar
Return guid
Catch ex As SqlException
mymsgbox(ex.Message)
Return Nothing
Finally
If Not IsNothing(mycmd) Then
mycmd.Dispose()
mycmd = Nothing
End If
If Not IsNothing(con) Then
con.Close()
con.Dispose()
con = Nothing
End If
End Try
End Function
---------------------------------------------------------------------------------------------------------------------------------------------------