Microsoft
Software
Hardware
Network
Question : asp.net I am trying to read and convert the @@IDENTITY value - it works in one of my Procs. - but not in another
I have this working in this proc. where is a SqlDataSource1_Insert....
I can get the SELECT @@IDENTITY value and convert it to an integer.
--------------------------
----------
----------
----------
----------
----------
--------
Protected Sub SqlDataSource1_Inserted(By
Val sender As Object, ByVal e As System.Web.UI.WebControls.
SqlDataSou
rceStatusE
ventArgs)
' Save the picture into database
' Get the new recordId
Dim id As Integer
Using command As SqlCommand = DirectCast(e.Command.Conne
ction.Crea
teCommand(
), SqlCommand)
command.CommandType = CommandType.Text
command.CommandText = "SELECT @@IDENTITY"
id = Convert.ToInt32(command.Ex
ecuteScala
r())
End Using
' Get the image id
Dim imageId As String = id.ToString()
' Get the ILoad Control
Dim picture1 As ILoad = DirectCast(Me.FormView1.Ro
w.FindCont
rol("pictu
re1"), ILoad)
' Update image files in database
'WebImage.SynchronizeCusto
mStorage(p
icture1.Va
lue, Director.Ex_E_204_ILoad1_I
nternalCod
e, imageId)
picture1.SynchronizeCustom
Storage(im
ageId)
End Using
End Sub
--------------------------
----------
----------
----------
-
I cannot convert it in this procedure???
--------------------------
----------
----------
----------
-
Protected Sub btnLoadImageSet1_Click(ByV
al sender As Object, ByVal e As System.EventArgs)
Dim id As Integer
Dim Connection1 As New SqlConnection("Data Source=DENNISWEST8101\SQLE
XPRESS;Ini
tial Catalog=Used_trucks;User ID=westdh12;Password=xxxx;
Integrated
Security=True")
'Create Command object
Dim nonqueryCommand As SqlCommand = Connection1.CreateCommand(
)
Connection1.Open()
nonqueryCommand.CommandTex
t = "SELECT @@IDENTITY"
id = Convert.ToInt32(nonqueryCo
mmand.Comm
andText)
It fails here with the error message...
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 131: nonqueryCommand.CommandTex
t = "SELECT @@IDENTITY"
Line 132:
id = Convert.ToInt32(nonqueryCo
mmand.Comm
andText)
Line 133:
Line 132
End Sub
Answer : asp.net I am trying to read and convert the @@IDENTITY value - it works in one of my Procs. - but not in another
Hi,
you cant use it like that. @@identity gives you the identity value from the latest insert in the current session. As no insert is exeuted you will get null. What is it you want to do?
/peter
Posted via EE Mobile
Random Solutions
Configuring Exchange Mail on Ipad
Sharepoint 2010 - Manage Content & Structure ...Where is it?
Editing the Windows Message "Your Account has Expired. Please contact your system administrator" for Windows XP Professional
I/O error reported on file system /oracle/P1U aix hdisk path vio
Can't access Exchange 2003 OWA from Internet
How to determine hard disk activities
How to trace a phone without installing the software?
Outlook Web App (OWA) 2010 defaults to light version for specific user
Mitel Teleworker One Way Audio
ftp put via php from linux to AS/400