Date conflict: how send to SQL, where the format of the value is acceptable?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I have a search page that the user can search the database for some or all of the items(db fields) available for search. I am creating the sql statement on fly. The problem is the format of date values. I read the value, but since I use portuguese version of visual studio the ShortDateString or LongDateString value of the given date is not acceptable by the SQL server because I will have to include that in the statement that I build. So I am not sure what is the best way to deal with this, or how to do this

Thanks in advance for your help

Reza
 
You can use DateTime.ParseExact method to read the date in Portuguese format and use the ToString("formatstring") of the DateTime object to format the date that's acceptable to your SQL server

(i.e. C#
DateTime dt = DateTime.ParseExact(str, "yyyyMMdd", null)
string str = dt.ToString("dd/MM/yyyy")

HTH
Suresh

----- Reza wrote: ----

Hello

I have a search page that the user can search the database for some or all of the items(db fields) available for search. I am creating the sql statement on fly. The problem is the format of date values. I read the value, but since I use portuguese version of visual studio the ShortDateString or LongDateString value of the given date is not acceptable by the SQL server because I will have to include that in the statement that I build. So I am not sure what is the best way to deal with this, or how to do this

Thanks in advance for your help

Reza
 
what is VB equivalent of the 3rd parameter in this call? DateTime.ParseExact(str, "yyyyMMdd", null)
doesn't accept null/NULL/system.dbnull or 0

Thanks

----- Suresh wrote: ----

You can use DateTime.ParseExact method to read the date in Portuguese format and use the ToString("formatstring") of the DateTime object to format the date that's acceptable to your SQL server

(i.e. C#
DateTime dt = DateTime.ParseExact(str, "yyyyMMdd", null)
string str = dt.ToString("dd/MM/yyyy")

HTH
Suresh

----- Reza wrote: ----

Hello

I have a search page that the user can search the database for some or all of the items(db fields) available for search. I am creating the sql statement on fly. The problem is the format of date values. I read the value, but since I use portuguese version of visual studio the ShortDateString or LongDateString value of the given date is not acceptable by the SQL server because I will have to include that in the statement that I build. So I am not sure what is the best way to deal with this, or how to do this

Thanks in advance for your help

Reza
 
Back
Top