Convert sql2000 timestamp field

  • Thread starter Thread starter Tim Kelley
  • Start date Start date
T

Tim Kelley

Is it possible to store a sql2000 timestamp field to a variable in C#. I am
creating a dataset from a stored procedure and one of the fields is a
timestamp field. I have created a variable of type binary[], but I am not
sure how to convert to data in the dataset.

Thanks.
 
And if I need to pass this value to a stored procedure do I need to convert
it back to a binary value? If so, how do I do this.

Thanks,


sloan said:
Select Convert( int , MyTimeStampColumn ) as MyTimeStampINT from
dbo.SomeTable

Then use it as an int in your c#

Use an alias so you keep it straight. (MyTimeStampINT is my alias)




Tim Kelley said:
Is it possible to store a sql2000 timestamp field to a variable in C#. I
am creating a dataset from a stored procedure and one of the fields is a
timestamp field. I have created a variable of type binary[], but I am
not sure how to convert to data in the dataset.

Thanks.
 
I'm guessing you're doing optimistic locking.

You just pass down the INT value to TSQL.


Something like this
uspEmployeeUpdate ( @EmpID int , @EmpRowVersINT int , @LastName
varchar(12) )


if exists ( select null from dbo.Employee where EmpID = @EmpID AND ((
Convert( int , EmpRowVers) <> @EmpRowVersINT )) )
begin
declare @errorMsg varchar(128)
select @errorMsg = 'Someone else updated this Employee Record
:< '

RAISERROR (@errorMsg, 16, 1)

RETURN

end

Update dbo.Employee Set LastName = @LastName where EmpID = @EmpID

return


You can probably use CAST instead of CONVERT. My longstanding habits are
hard to break.






Not perfectly "pretty" but the guts are there.





Tim Kelley said:
And if I need to pass this value to a stored procedure do I need to
convert it back to a binary value? If so, how do I do this.

Thanks,


sloan said:
Select Convert( int , MyTimeStampColumn ) as MyTimeStampINT from
dbo.SomeTable

Then use it as an int in your c#

Use an alias so you keep it straight. (MyTimeStampINT is my alias)




Tim Kelley said:
Is it possible to store a sql2000 timestamp field to a variable in C#.
I am creating a dataset from a stored procedure and one of the fields is
a timestamp field. I have created a variable of type binary[], but I am
not sure how to convert to data in the dataset.

Thanks.
 
Is it possible to store a sql2000 timestamp field to a variable in C#. I
am creating a dataset from a stored procedure and one of the fields is a
timestamp field. I have created a variable of type binary[], but I am
not sure how to convert to data in the dataset.
Select Convert( int , MyTimeStampColumn ) as MyTimeStampINT from
dbo.SomeTable

Then use it as an int in your c#

??? Books online says the timestamp data type is stored in 8 bytes. Last I
checked that wouldn't fit into an int....
 
Try bigint then.

The concept is correct. It just depends on how many updates you actually do
I guess.





Obviously,
Jeff Johnson said:
Is it possible to store a sql2000 timestamp field to a variable in C#.
I am creating a dataset from a stored procedure and one of the fields is
a timestamp field. I have created a variable of type binary[], but I am
not sure how to convert to data in the dataset.
Select Convert( int , MyTimeStampColumn ) as MyTimeStampINT from
dbo.SomeTable

Then use it as an int in your c#

??? Books online says the timestamp data type is stored in 8 bytes. Last I
checked that wouldn't fit into an int....
 
Back
Top