Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 25th, 2003, 03:24 PM
Elric Elric is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 3 Elric User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Like Operator Not Working With Linked SQL Server Table

I have the same sql statement to generate a recordset, that I have to set a forms recordsource. The recordsource works fine, the recordset will not retrieve any rows using the LIKE operator. Here is the code: Any ideas? Thanks.


On Error GoTo Err_cmdSearch_Click

Dim search_str As String
Dim position1 As Integer
Dim position2 As Integer
Dim search_strA As String
Dim position1A As Integer
Dim position2A As Integer
Dim new_recordset As String
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sSQL As String


search_str = Form_Customer!txt_name_search.Value
position1 = InStr(search_str, "*")
position2 = InStr(position1 + 1, search_str, "*")

search_str = Replace(search_str, "*", "")

If position2 <> 0 Then
search_str2 = "*" & search_str & "*"
Else
search_str2 = search_str & "*"
End If


sSQL = "SELECT * FROM dbo_Customer WHERE (((CustName) Like '" & search_str2 & "'));"
'sSQL = "SELECT * FROM dbo_Customer WHERE (((dbo_Customer.CustName) = 'FULTON SUPPLY COMPANY'));"

Set cnn = CurrentProject.Connection
'Set cnn = New ADODB.Connection
'cnn.Open "File Name=C:\SQLSERVERLINK.dsn"

Set rst = New ADODB.Recordset
'rst.Open sSQL, cnn, adOpenDynamic, adLockPessimistic
rst.Open "SELECT * FROM dbo_Customer WHERE (((CustName) Like '" & search_str2 & "'));", cnn, adOpenDynamic, adLockPessimistic
MsgBox rst.Source
rst.MoveFirst
MsgBox rst!CustName


Form_Customer.RecordSource = sSql
Form_Customer.Requery
Form_Customer.Refresh


Exit_cmdSearch_Click:
Exit Sub

Err_cmdSearch_Click:
MsgBox Err.Description
Resume Exit_cmdSearch_Click

End Sub

Reply With Quote
  #2  
Old August 25th, 2003, 06:32 PM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
what happens if you try
Code:
  .... LIKE '%value%'
?
__________________
- Rogier Doekes

Reply With Quote
  #3  
Old August 26th, 2003, 11:28 AM
Elric Elric is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 3 Elric User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
"SELECT * FROM dbo_Customer WHERE (((dbo_Customer.CustName) = '%F%'));"


rst.Open sSQL, cnn, adOpenDynamic, adLockPessimistic
MsgBox rst.Source
rst.MoveFirst
MsgBox rst!CustName

Same thing: On the movefirst - Either BOF or EOF is true

Is % the wildcard for SQL Server?



Thanks,
Elric

Reply With Quote
  #4  
Old August 26th, 2003, 12:36 PM
Elric Elric is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 3 Elric User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Upon further review, it did work.... once I changed the = back to LIKE :-)


Thanks, bud

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Like Operator Not Working With Linked SQL Server Table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway