D
Dan
Hi,
after inserting a record in a table (sql server), i need the last value of
the primary key of that table, which increments automatically, before
inserting that value in another table.
I did like this:
comd.CommandText = "insert into [mytable] (field1, field2) values(@datbeg
,@datend')"
comd.Parameters.Add("@datbeg", SqlDbType.DateTime).Value = tda
comd.Parameters.Add("@datend", SqlDbType.DateTime).Value = tda2
connection.Open()
comd.CommandText = "DECLARE @orderid int"
comd.CommandText = "SET @orderid = SCOPE_IDENTITY()"
comd.CommandText = "select @orderid"
Dim x As Integer
x = Convert.ToInt32(comd.ExecuteScalar())
This giives an error:
"error: Must declare the scalar variable "@orderid". "
Thanks
Dan
after inserting a record in a table (sql server), i need the last value of
the primary key of that table, which increments automatically, before
inserting that value in another table.
I did like this:
comd.CommandText = "insert into [mytable] (field1, field2) values(@datbeg
,@datend')"
comd.Parameters.Add("@datbeg", SqlDbType.DateTime).Value = tda
comd.Parameters.Add("@datend", SqlDbType.DateTime).Value = tda2
connection.Open()
comd.CommandText = "DECLARE @orderid int"
comd.CommandText = "SET @orderid = SCOPE_IDENTITY()"
comd.CommandText = "select @orderid"
Dim x As Integer
x = Convert.ToInt32(comd.ExecuteScalar())
This giives an error:
"error: Must declare the scalar variable "@orderid". "
Thanks
Dan