NealR
NealR

Reputation: 10709

Convert SQL date datatype to string

I am writing something in VB and need to convert a SQL date (not datetime) into a string. This should be an easy convertion, however toString does not work and I cannot find anything online . The part of the code I'm working on looks like this:

    Dim incomingDate As String
    incomingDate = row.Cells(5).Text.ToString()

When the data being put in the gridview is a DateTime datatype this works fine. If it's simply Date, it gives me the following error message:

"Specified argument was out of the range of valid values. Parameter name: index"

I've also tried this work-around but it didn't work

    Dim incomingDate As String
    Dim d As New DateTime
    d = DateTime.Parse(row.Cells(5).Text)

    incomingDate = Date.Parse(row.Cells(5).Text)

Same error...

Upvotes: 1

Views: 1926

Answers (1)

Dan Pichelman
Dan Pichelman

Reputation: 2332

In SQL you can use convert(varchar, mySqlDate, 101) to emit a string instead of a date. Is that what you had in mind?

Upvotes: 1

Related Questions