smalldatetime problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: smalldatetime problem

  1. #1
    Join Date
    Feb 2004
    Posts
    126

    smalldatetime problem

    i'm passing a string as a Date as value :- for example "23/07/1988"
    But when trying to insert it in a column with datatype "smalldatetime" i get
    an error
    The string was not recognized as a valid DateTime. There is a unknown word
    starting at index 0.
    any ideas

  2. #2
    Join Date
    Dec 2004
    Posts
    717
    when trying to insert it in a column with datatype "smalldatetime"
    Could you please tell us more clear?
    the column of What? grid?

    may be you can use convert funct..
    string str="23/07/1988";
    DateTime dt = Convert.ToDateTime(str);
    [ but i'm not so sure.. I think you should give more detail.... ]
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Please post the code you're using to insert the date value into the database.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  4. #4
    Join Date
    Feb 2004
    Posts
    126
    I'm passing a string like this:-
    DOB = '29/06/1974' as you can see in my hyperlink
    AddToProdcut.aspx?productID=105&DOB=29/06/1974&AccNo=23423
    and then on the addToProduct page i grab the
    Dim DOB As String = Request.Params("DOB")
    and insert it in a Sub below using SqlParameters

    'Adding the String value here
    cart.AddProduct(DOB)

    'this is the VB class that has the SUB program
    Public Sub AddProduct(ByVal DOB As String)
    Dim parameterDOB As SqlParameter = New SqlParameter("@DOB", SqlDbType.SmallDateTime, 4)
    'Dim DOB As DateTime
    'parameterDOB.Value = "29/06/1974"
    parameterDOB.Value = DOB
    myCommand.Parameters.Add(parameterDOB)

    in my stored procedure i have it set to :- SET @DOB = convert(smalldatetime, @DOB, 120) and the DOB datatype is smalldatetime

    I want to be able to input my date in this format ="DD/MM/YYYY"
    But then i do that i get error "String was not recognized as a valid DateTime"
    But when i input ="MM/DD/YYYY" its fine..
    How can i format it so that i can input it has :- "DD/MM/YYYY"
    Any ideas

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try this:

    Dim DOB As String = Request.Params("DOB")
    Dim format As New System.Globalization.CultureInfo("en-gb", True)
    Dim DateOfBirth As DateTime = DateTime.Parse(DOB, format)

    Then pass DateOfBirth as a DateTime to your AddProduct method.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  6. #6
    Join Date
    Feb 2004
    Posts
    126
    Thx Phil
    i was setting Globalization in my web.config eearlier and it wasn't reflecting en-GB
    it kept using en_US.
    Thx for the promt reply and it did the trick..

  7. #7
    Join Date
    Feb 2004
    Posts
    126
    Phil thanks for the last post but after adding other Strings to add to my method "AddProduct"
    I get error at line 56 (the error is :- String reference not set to an instance of a String. Parameter name: s ):-
    Line 54: Dim DOB As String = Request.QueryString("DOB")
    Line 55: Dim format As New System.Globalization.CultureInfo("en-gb", True)
    Line 56: Dim DateOfBirth As DateTime = DateTime.Parse(DOB, format)

    Any help thanks

  8. #8
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    That error occurs if DOB is null; sounds like you're not receiving a DOB parameter in the QueryString. You can avoid the error by checking that DOB is not null:
    Code:
    Dim DOB As String = Request.QueryString("DOB")
    If Not DOB Is Nothing Then
        Dim format As New System.Globalization.CultureInfo("en-gb", True)
        Dim DateOfBirth As DateTime = DateTime.Parse(DOB, format)
        cart.AddProduct(DOB)
    End If
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  9. #9
    Join Date
    Feb 2004
    Posts
    126
    Thx phil for the reply i'm sure that would do the trick.
    Actually i was checking for the other string values for NULL i just didn't think of that.
    Will let you know how it goes
    Patrick

Similar Threads

  1. Problem with Search
    By Irina in forum ASP.NET
    Replies: 0
    Last Post: 11-29-2002, 11:47 PM
  2. Replies: 0
    Last Post: 12-13-2001, 01:06 PM
  3. a problem with font and language
    By Roseta in forum VB Classic
    Replies: 0
    Last Post: 11-14-2001, 04:24 AM
  4. Arabic problem view
    By Ayman in forum VB Classic
    Replies: 0
    Last Post: 04-03-2000, 02:08 AM
  5. Problem with CryptoAPI and JCE
    By Jason Bock in forum VB Classic
    Replies: 0
    Last Post: 03-21-2000, 07:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center