Results 1 to 22 of 22

Thread: using sql statment

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    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

  2. #2
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    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.

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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:
    1. 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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    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

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    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

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  9. #9
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    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

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    Re: using sql statment

    and i tried the code that given to me'it didn't work(the vb basic code)

  12. #12
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: using sql statment

    So what is the error or does it just not return anything?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    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

  14. #14
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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:
    1. sqlstr="select * from " & editdata.database.tabledefs(i).name & " where status like '%התראה%'
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    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

  16. #16
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    Re: using sql statment

    the sql is:select * from " & editdata.database.tabledefs(i).name & " where status like '%התראה%'
    the error is error number 3011
    omer

  18. #18
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    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?

  20. #20
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    93

    Re: using sql statment

    so,how can i resolve the problem??
    in the isreali forums they didn't answer...here it's faster
    omer

  22. #22
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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
  •  



Click Here to Expand Forum to Full Width