|
-
Oct 17th, 2006, 07:55 AM
#1
Thread Starter
Lively Member
using sql statment
hi,
i want to use sql statment with vb the example:
i need to search any record the contains 'abc'
how am i doing it with like statment and vb?
omer
-
Oct 17th, 2006, 07:57 AM
#2
Frenzied Member
Re: using sql statment
What have you tried that doesn't work?
Beantown Boy
Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
-
Oct 17th, 2006, 08:03 AM
#3
Re: using sql statment
Like this:
First you need a connection to the database that is made and opened.
Second a recordset object declared and initiated.
Dim a string var as strSQL
Set the strSQL value like this:
VB Code:
strSQL = "Select [i][b]fieldname,fieldname,..... things being returned[/b][/i] From [i][b] tableName to be seached[/b][/i] Where [i][b] fieldname to seach [/b][/i] Like '%abc%'"
Now open the recordset and test if any records returned.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2006, 08:11 AM
#4
Thread Starter
Lively Member
Re: using sql statment
i tried to search a word(abc for example) in the tables with the statment like
i didn't understand the vb basic code
-
Oct 17th, 2006, 08:18 AM
#5
Re: using sql statment
What was the code that you had/have that you didn't understand?
Also, what database are you using? The characters supported by LIKE differ between Access and SQL Server.
-
Oct 17th, 2006, 08:47 AM
#6
Thread Starter
Lively Member
Re: using sql statment
i didn't understood that code:
strSQL = "Select fieldname,fieldname,..... things being returned From tableName to be seached Where fieldname to seach Like '%abc%'"
i'm using access database
omer
-
Oct 17th, 2006, 08:48 AM
#7
Re: using sql statment
Hack I use the same character with SQL Server and Access if I am doing the Connection from VB and it works on boths. If using Access exclusively (the code is written in Access) then the character makes a differance.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2006, 08:50 AM
#8
Re: using sql statment
Well, we can't give you specific examples because we don't know what your field names are nor do we know the name of your database or their tables.
So, Gary's example, using Field1, Field2, etc and tablename was just using generics.
So, take what he did, plug in the real field names and table name and give it a shot.
-
Oct 17th, 2006, 08:51 AM
#9
Re: using sql statment
Is the code written in VB or Access. Look in the thread: http://www.vbforums.com/showthread.php?t=349994 for a tutorial on using ADO with VB6 and databases.
Take a look here: http://sqlcourse.com/ for a SQL tutorial
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2006, 09:35 AM
#10
Thread Starter
Lively Member
Re: using sql statment
i'm searching word in hebrew התראה in field status the tables are all the tables in the database
(that contains status'for each table in the db there is status table )
how can i search the word with sql and vb?
omer
-
Oct 17th, 2006, 09:40 AM
#11
Thread Starter
Lively Member
Re: using sql statment
and i tried the code that given to me'it didn't work(the vb basic code)
-
Oct 17th, 2006, 10:35 AM
#12
Re: using sql statment
So what is the error or does it just not return anything?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2006, 10:40 AM
#13
Thread Starter
Lively Member
Re: using sql statment
the error is: can't find object *התראה* the code is:
sqlstr="select * from "+editdata.database.tabledefs(i).name+ "where status like *התראה*
the table exist,i checked it
-
Oct 17th, 2006, 10:58 AM
#14
Re: using sql statment
First the status after like need to be inside single qoutes (I'm assuming here that you are seaching on a text field.), second the * should be a % if you are passing this from VB and * is doing all this from inside Access.
Like this:
VB Code:
sqlstr="select * from " & editdata.database.tabledefs(i).name & " where status like '%התראה%'
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2006, 11:23 AM
#15
Thread Starter
Lively Member
Re: using sql statment
i wrote it exactly like that'the editor added " in the end of the line
and the error still exist
what could be the problem?
omer
-
Oct 17th, 2006, 11:46 AM
#16
Re: using sql statment
Please post the exact sql that is being generated by the application. Set a break point and get the query of do a debug print to the immediate window and post the statement back here.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2006, 12:07 PM
#17
Thread Starter
Lively Member
Re: using sql statment
the sql is:select * from " & editdata.database.tabledefs(i).name & " where status like '%התראה%'
the error is error number 3011
omer
-
Oct 17th, 2006, 12:13 PM
#18
Re: using sql statment
I want to see the actual sql that is being sent to the application. Not the statement you wrote to build the SQL. Do you know how to get that actual statement to print out?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2006, 12:58 PM
#19
Thread Starter
Lively Member
Re: using sql statment
i did it with debug.print sqlstr
and that is the result:
"select * from 0331345status where status like '%התראה%'"
explain:status is name of column in the table 0331345status
what can be wrong here?
-
Oct 17th, 2006, 01:19 PM
#20
Re: using sql statment
I think it is having a problem translating the hebrew charaters. When I created a table with the same name an posted the characters you were seaching form I also got nothing when I removed the where condition and just retrieved the data I go ????? as the text in the field.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 17th, 2006, 02:17 PM
#21
Thread Starter
Lively Member
Re: using sql statment
so,how can i resolve the problem??
in the isreali forums they didn't answer...here it's faster
omer
-
Oct 17th, 2006, 02:38 PM
#22
Re: using sql statment
Sorry I don't think I'll be able to help here then.
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|