G
Glyn Williams
Hi,
I'm trying to get the ID of a newly created record into a variable, so I can
display it in a Label or something after being created. I know you can use
@@identity in the sql statement, but I just can't seem to get it to go.
Any help appreciated,
Glyn Williams
Here is my code:-
Public Sub addBike(Sender As Object, E As EventArgs)
Dim myCommand As new SqlCommand()
Dim myConnection As New SqlConnection
("server=Tron;database=sellmybike;Integrated Security=SSPI")
myCommand.Connection = myConnection
'Define insert command
myCommand.CommandText="INSERT INTO Details
(PostDate,Name,Town,County,Seller,Email,Tel,Make,Model,ManYear,Mileage,Price
,Details) VALUES (
@PostDate,@Name,@Town,@County,@Seller,@Email,@Tel,@Make,@Model,@ManYear,@Mil
eage,@Price,@Details)"
myCommand.Parameters.Add ("@PostDate", Now())
myCommand.Parameters.Add ("@Name", msgName.Value)
myCommand.Parameters.Add ("@Town", msgTown.Value)
myCommand.Parameters.Add ("@County", msgCounty.Value)
myCommand.Parameters.Add ("@Seller", msgSeller.Value)
myCommand.Parameters.Add ("@Email", msgEmail.Value)
myCommand.Parameters.Add ("@Tel", msgTel.Value)
myCommand.Parameters.Add ("@Make", msgMake.Value)
myCommand.Parameters.Add ("@Model", msgModel.Value)
myCommand.Parameters.Add ("@ManYear", msgManYear.Value)
myCommand.Parameters.Add ("@Mileage", msgMileage.Value)
myCommand.Parameters.Add ("@Price", msgPrice.Value)
myCommand.Parameters.Add ("@Details", msgDetails.Value)
myCommand.Connection.Open()
'update the tape
myCommand.ExecuteNonQuery()
'Im sure some code must go here and in the sql statement
myCommand.Connection.Close()
End Sub
I'm trying to get the ID of a newly created record into a variable, so I can
display it in a Label or something after being created. I know you can use
@@identity in the sql statement, but I just can't seem to get it to go.
Any help appreciated,
Glyn Williams
Here is my code:-
Public Sub addBike(Sender As Object, E As EventArgs)
Dim myCommand As new SqlCommand()
Dim myConnection As New SqlConnection
("server=Tron;database=sellmybike;Integrated Security=SSPI")
myCommand.Connection = myConnection
'Define insert command
myCommand.CommandText="INSERT INTO Details
(PostDate,Name,Town,County,Seller,Email,Tel,Make,Model,ManYear,Mileage,Price
,Details) VALUES (
@PostDate,@Name,@Town,@County,@Seller,@Email,@Tel,@Make,@Model,@ManYear,@Mil
eage,@Price,@Details)"
myCommand.Parameters.Add ("@PostDate", Now())
myCommand.Parameters.Add ("@Name", msgName.Value)
myCommand.Parameters.Add ("@Town", msgTown.Value)
myCommand.Parameters.Add ("@County", msgCounty.Value)
myCommand.Parameters.Add ("@Seller", msgSeller.Value)
myCommand.Parameters.Add ("@Email", msgEmail.Value)
myCommand.Parameters.Add ("@Tel", msgTel.Value)
myCommand.Parameters.Add ("@Make", msgMake.Value)
myCommand.Parameters.Add ("@Model", msgModel.Value)
myCommand.Parameters.Add ("@ManYear", msgManYear.Value)
myCommand.Parameters.Add ("@Mileage", msgMileage.Value)
myCommand.Parameters.Add ("@Price", msgPrice.Value)
myCommand.Parameters.Add ("@Details", msgDetails.Value)
myCommand.Connection.Open()
'update the tape
myCommand.ExecuteNonQuery()
'Im sure some code must go here and in the sql statement
myCommand.Connection.Close()
End Sub