Aspx page wont search a database

By MatthewvanBuuren ·
I have a aspx page written in Vb and one of my button_click events has a function to connect to a sql database and retieve the data of a specific record by using the sql statement "SELECT * FROM Calendar WHERE Day="27" " The Name of my Table is Calendar. The RColum Names are Id ,Day ,Month and Year. If i use the sql statement and only write SELECT * FROM Calendar it finds the first record and i can use it but when i add WHERE i get an error saying "Cannot find column 27 and Cannot find column November and Cannot find column 2009 which is what im searching for ??? Any Ideas?

Dim frmDay As String = "27"
Dim frmMonth As String = "November"
Dim frmYear As String = "2009"
Dim strSql As String = ("SELECT * FROM Calendar;")

Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = *****
Dim myCommand As System.Data.SqlClient.SqlCommand
Dim myReader As System.Data.SqlClient.SqlDataReader

myCommand = New System.Data.SqlClient.SqlCommand(strSql, con)
myReader = myCommand.ExecuteReader

While myReader.Read()
If myReader(1).ToString = DrpDay.Text Then
If myReader(2).ToString = DrpMonth.Text Then
If myReader(3).ToString = DrpYear.Text Then
lbl1.Text = "The Date :" & myReader(1).ToString() & "/" & myReader(2).ToString & "/" & myReader(3).ToString
End If
End If
End If
End While

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -


by Shellbot In reply to Aspx page wont search a d ...

Is the above example exactly as you have it in your code?

"SELECT * FROM Calendar WHERE Day="27" "

What data type is DAY?
If its an integer, you don't need quotes around it. I'd have thought as its a number, you wouldn't be using char. As a note, unless you've configured it specificaly, shouldn't be using double quotes in a query anyways.

Related Discussions

Related Forums