Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have the following cade that takes the date from a calander control and then extracts the required field from a database.

 

Dim fdate As Date

Dim fday As Integer

 

fday = fday - Weekday(Me.DateTimePicker1.Value.Date, 0) + 1

fdate = DateAdd("d", +fday, Me.DateTimePicker1.Value.Date)

 

Dim mycommand As New OleDbCommand("SELECT * from tblgym WHERE Gdate = #" & Format(fdate, "G") & "#", MyConnection)

Dim MyReader As OleDbDataReader = mycommand.ExecuteReader()

MyReader.Read()

 

I have tried to format the date but can not seem to change it

 

Format(fdate, "DD/MM/YYYY")

and

Format(fdate, "ddmmyyy")

 

but I just get the follwoing error

 

Additional information: Cast from string "DD/04/YYYY" to type 'Date' is not valid.

 

I have also tried to format it in the SQL statement

 

as Format(fdate,"yyyymmdd") as I have done that before in Access but the program breaks on the following line

 

 

Dim MyReader As OleDbDataReader = mycommand.ExecuteReader()

 

Any Ideas as this is driving me nuts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...