Search text in SQL Express 2008 database error

NewComer

Active member
Joined
Jan 2, 2010
Messages
34
Programming Experience
Beginner
I have a SQL Express 2008 database with table GuestInfo having 1 column Col1 defined as Text with allow NULL & another column Col2 defined as Int with allow NULL

If I use command:

cmd.CommandText = "SELECT * FROM GuestInfo WHERE Col2 = 12345"
Dim lrd As SqlDataReader = cmd.ExecuteReader()


- There is no error happen

But if I use:

cmd.CommandText = "SELECT * FROM GuestInfo WHERE Col1 = 'ABC' "
Dim lrd As SqlDataReader = cmd.ExecuteReader()


- There is an error pop-up said: Connect to SQL Server, data types text and varchar are incompatible in the equal to operator

Then I tried the following:

Dim str As String
str = "ABC"
cmd.CommandText = "SELECT * FROM GuestInfo WHERE Col1 = '" & str & "'"
Dim lrd As SqlDataReader = cmd.ExecuteReader()


- same error happen

If I use: cmd.CommandText = "SELECT * FROM GuestInfo WHERE Col1 = Convert(text,'ABC')"

- Then error pop-up said: Connect to SQL Server, data types text and text are incompatible in the equal to operator

--------------------------------------------------------------------------

What can I do for this issue (I must search Col1 with "ABC")?

1. Change Col1 to another type in my SQL database, but which one?

2. Change to another command: cmd.CommandText = "SELECT * FROM GuestInfo WHERE Col1 = ??????? "

Thanks to any help
 
It is Ok now

I got help & re-define Col1 to varchar(50) then use:

cmd3.CommandText = "SELECT * FROM GuestInfo WHERE Trial = 'ABC' "
Dim lrd As SqlDataReader = cmd3.ExecuteReader()


Now there is no ore error

Cheers :D
 
Back
Top