Convert sql2000 timestamp field

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.
 
T

Tim Kelley

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.
 
S

sloan

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.
 
J

Jeff Johnson

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....
 
S

sloan

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top