SunQuest
 
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old July 9th, 2004, 03:29 PM
Kristin Kristin is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 56 Kristin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
SQL queries

Here is my issue, I am referencing an SQL query through a command in the dataenvironment. My question is, where and how do I use a wildcard to return values? For example, I am looking for all companies in a table that begin with "Her" here is the command code I am using but I have to enter the exact name of the company to find it...ie. "Heritage Enterprises" - where txtCompany is the variable I am using.

Private Sub cmdFilter_Click()
' run the query, passing the expected parameters.
DataEnvironment1.SearchCompany txtCompany, txtLocation, txtConfname1

' Ensure the grid is bound to the DataEnvironment
Set DataGrid1.DataSource = DataEnvironment1
DataGrid1.DataMember = "SearchCompany"
End Sub

any ideas anyone? is it something I put in the code here or do I do it in the SQL query???

help! I'm really new at this all, sorry!

Reply With Quote
  #2  
Old July 9th, 2004, 04:54 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,738 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 1 h 34 m 28 sec
Reputation Power: 443
Code:
SELECT *
FROM TableName 
WHERE Companies LIKE 'Her%'

Reply With Quote
  #3  
Old July 9th, 2004, 05:06 PM
Kristin Kristin is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 56 Kristin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Actually, here is the query(command), written in SQL.. that is being called in VB as "SearchCompany

SELECT entered, mrocomid, compwksid, company, random,
location, add1, add2, city, state, zip, confname1, conlname1,
conphone1, conext1, conemail1
FROM company
WHERE (company = ?) OR
(location = ?) OR
(confname1 = ?)
ORDER BY company, location

I am using a variable in VB for each "?" for users to search for matching companies. The "variables are the txtCompany, txtLocation, and txtConfname1 you see in my vb code. The problem is I need the girls here to type into a text box "Her" and have it return all the companies that start with HER...... They don't have access to the actual query, only the form that is referencing it....

Reply With Quote
  #4  
Old July 9th, 2004, 05:48 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,738 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 1 h 34 m 28 sec
Reputation Power: 443
try
Code:
SELECT entered, mrocomid, compwksid, company, random, 
location, add1, add2, city, state, zip, confname1, conlname1, 
conphone1, conext1, conemail1
FROM company
WHERE (company LIKE ? OR company LIKE ?%) OR
(location = ?) OR
(confname1 = ?)
ORDER BY company, location

Reply With Quote
  #5  
Old July 9th, 2004, 06:12 PM
Kristin Kristin is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 56 Kristin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
hmm, no luck. the query doesn't return anything

Reply With Quote
  #6  
Old July 9th, 2004, 06:37 PM
Kristin Kristin is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 56 Kristin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
K, I figured it out....


I use LIKE ?

then in my txtCompany box I enter for instance Her%

that returns all companies beginning with Her. Now I jsut have to figure out a way to have it automatically enter the % sign after an entry into a text box - trying to simplify for the users...

thanks again for the input!

Reply With Quote
  #7  
Old August 10th, 2004, 11:45 AM
revilohm revilohm is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: North Carolina
Posts: 1 revilohm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Kristin,

I am writing a progran to allow many similar options to users and thought you might be interseted in how I do it.

My approach to wildcards is to use one at the beginning and end of the txtCompany.Text variable. These can be turned on or off by the user.

This approach allows the following options:
1. When the front wildcard is off then it means that SQLfield must start with txtCompany.Text
2. When the Back wildcard is off then it means that SQLfield must end with txtCompany.Text
3. When Both are Off then SQLField must be equal to txtCompany.Text
4. When Both are on then SQLField must contain txtCompany.Text

I place a small CommandButton on either side of the txtCompany box . Each CommandButton (cmdBtn1 & cmdBtn2) toggles a string variable that is either NULL or equal to the SQL wildcard symbol (%). I also use a CommandButton (cmdFind) to activate the search. (See an actual Form from one of my programs in the attachment.) Note: The Combo1 box in the example is my SqlField variable in this program.

Code Follows

'************************************************* **************
SUB cmdBtn1_Click()
'This subroutine toggles the front wildcard Status On and Off as the button is pressed.
' (Actually, I use an asterisk (*) to indicate that the wildcard is "On"
' and I use a Blank faced button to indicate that the wildcard is "Off")
If Variable1="" then
Variable1="%"
cmdBtn1.Caption = "On"
Else
Variable1="" then
cmdBtn1.Caption = "Off"
End If
END SUB
'************************************************* **************
SUB cmdBtn2_Click()
'This subroutine toggles the back Wildcard status On and Off as the button is pressed.
' (Actually, I use an asterisk (*) to indicate that the wildcard is "On"
' and I use a Blank faced button to indicate that the wildcard is "Off")
If Variable2="" then
Variable2="%"
cmdBtn2.Caption = "On"
Else
Variable2="" then
cmdBtn2.Caption = "Off"
End If
END SUB
'************************************************* **************
SUB cmdFind_Click()
'This routine performs the search based on the wildcard/txtCompany inputs.

'Combine the strings into one string that is used in the SqlQuery
sqlQuery= "Select * from sqlTable where sqlField like '" & Variable1 & txtCompany.Text & Variable2 & "' "

'Execute the SqlQuery using the ADODC
With ADODC1
.RecordSource = sqlQuery
.Refresh
End With

'Update and refresh the DataGrid
With DataGrid1
.ReBind
.Refresh
End With
END SUB
'************************************************* **************

Hope this helps,
Hunter
Attached Images
File Type: jpg Form.jpg (58.4 KB, 174 views)

Reply With Quote
  #8  
Old August 10th, 2004, 03:27 PM
Kristin Kristin is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 56 Kristin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Excellent idea! I am definitely going to use this

thanks!
Kristin

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > SQL queries


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 3 hosted by Hostway