Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Database > SQL Server > SQL Server Express

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-30-2010, 9:24 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Jan 2010
Posts: 14
Reputation: 5
NewComer is on a distinguished programming path ahead
Default Search text in SQL Express 2008 database error

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-30-2010, 9:54 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Jan 2010
Posts: 14
Reputation: 5
NewComer is on a distinguished programming path ahead
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 9:37 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.