Showing posts with label converting. Show all posts
Showing posts with label converting. Show all posts

Saturday, February 11, 2012

"Converting numbers into Dates"

I'm working in Access 2000. I was given some tables with number (long integer) data types for dates, such as 20041011 for Oct. 11, 2004. How can I convert these rows of numbers into dates? in order to re-format the table to accept them as dates?

I prefer to do this within the sql statement (update query, etc). What is the sql syntax to do this? (assume the column name is Notdate). Thanks!!!For Access you can do it like this

UPDATE Tablename
SET [NotDate] = DateSerial(Int(Left([notDate],4)),Int(Left(Right([NotDate],4),2)),INT(Right([NotDate],2)));|||It seems a better idea to me to create a second column D with datatype Date to store the result in:

UPDATE tablename SET D = DateSerial(...

"Conversion failed when converting from a character string to uniqueidentifier."

This is probably a simple wuestion but i would appreciate some help

I am trying to get and insert theuserId into a table called "Orders"

I got the user id as

Dim CustomerId As Object = Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString

The button on click command is

worldshop.ShoppingCart.CreateOrder(CustomerId,...................

The Function Has the parameter for Customer Id as follows

Dim dbParam_CustomerId As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_CustomerId.ParameterName = "@.CustomerId"
dbParam_CustomerId.Value = CustomerId
dbParam_CustomerId.DbType = System.Data.DbType.String
command.Parameters.Add(dbParam_CustomerId)

When i run this I am getting the error message

"Conversion failed when converting from a character string to uniqueidentifier."

Can anyone tell me where I am going wrong


many thanks

Martin

What type is CustomerID defined as in the database? It sounds like it is NOT a string, but rather a uniqueidentifier (a GUID).|||

thanks for your reply. i got it sorted out

martin

|||Do you mind sharing with us what your solution was? as I am having the same problem...|||

I'll check and get back to you

martin

|||

sorry about the delay in getting back to you

I was having the same problem. I solved it by instantiating the userid as an object

Dim userId As Object = Membership.GetUser(User.Identity.Name).ProviderUserKey

i passed the object to the function as a guid

ByVal userId As Guid
Dim dbParam_userId As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_userId.ParameterName = "@.UserId"
dbParam_userId.Value = userId
dbParam_userId.DbType = System.Data.DbType.Guid
command.Parameters.Add(dbParam_userId)

last i put the guid into the database as char 36

@.UserId char (36)

HTH