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

con.Open()
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
con.Close()

Dizzzy,

SELECT * FROM Calendar where dayno=27
SELECT * FROM Calendar where dayno='27'

The Data Type for the Column Day is Text and so are all the columns so surely syntax is

SELECT * FROM Calendar WHERE Day="27"

Wrap non-numeric numeric valuw with single quote.

SELECT * FROM [Calendar] WHERE [Day]='27'

Ok i changed it to

SELECT * FROM Calendar WHERE Day='27'

This seems to work but now i get another error message
"The data types text and varchar are incompatible in the equal to operator"

Ok i think ive got it now ThankYou aDataPost you are a life saver ive looked over that code a hundred times and it never occured to me to look at the single quotes

Ok i changed it to

SELECT * FROM Calendar WHERE Day='27'

This seems to work but now i get another error message
"The data types text and varchar are incompatible in the equal to operator"

Comparison operators can be used on all expressions except expressions of the text, ntext, or image data types.

Also use text data type if you are going to store a large amout of text in day column. Otherwise change to varchar or nvarchar.

The above SELECT statement will work with text type column if you change as below

SELECT * FROM Calendar WHERE Day LIKE '27'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.