Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have changed my data typeto text in my Access database, but I am still not getting any results. This is my code:

 

Private Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged

Dim strSelected As String = Calendar1.SelectedDate.Date.ToShortDateString

Dim STRs As Date = CDate(strSelected)

myDA = New OleDbDataAdapter("SELECT * " & _

"FROM EventsTable " & _

"WHERE EventDate= '" & strSelected & "'", myConnection)

 

dsSelDate = New DataSet

myDA.Fill(dsSelDate)

If dsSelDate.Tables(0).Rows.Count = 0 Then

DataGrid1.Visible = False

Else

DataGrid1.Visible = True

DataGrid1.DataSource = dsSelDate

DataGrid1.DataBind()

End If

End Sub

 

I am choosing a date that has information and when I run the query in my database with the selected date, it works fine, but I can not get it to work in code.

 

Any ideas?

 

Chester

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

  • *Experts*
Posted

I believe you must use the number/pound sign to surround a Date in Access:

SELECT * FROM Table1 WHERE DateColumn = #12/31/1999#

 

In SQL Server you use single quotes:

SELECT * FROM Table1 WHERE DateColumn = '12/31/1999'

 

There's probably also some preferred format that Access will want - maybe "month/day/year" vs "year/month/day" etc.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

I got it to work. I put my SQL statement in a string variable and it works fine now :)

 

My only problem would be if I was working with a database that I could not change the data type to string and it stayed as a date.

 

Chester

____________________________________________

http://www.pophamcafe.com

I am starting a developers section, more tutorials than anything.

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...