By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Convert sql2000 timestamp field

P: n/a
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.
Nov 11 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <sl***@ipass.netwrote in message
news:eI**************@TK2MSFTNGP02.phx.gbl...
>

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" <tk*****@company.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>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.


Nov 12 '08 #2

P: n/a

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" <tk*****@company.comwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
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" <sl***@ipass.netwrote in message
news:eI**************@TK2MSFTNGP02.phx.gbl...
>>

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" <tk*****@company.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>>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.



Nov 12 '08 #3

P: n/a
"sloan" <sl***@ipass.netwrote in message
news:eI**************@TK2MSFTNGP02.phx.gbl...
>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....
Nov 12 '08 #4

P: n/a
Try bigint then.

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

Obviously,
"Jeff Johnson" <i.***@enough.spamwrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
"sloan" <sl***@ipass.netwrote in message
news:eI**************@TK2MSFTNGP02.phx.gbl...
>>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....

Nov 12 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.