SQL Questions

Discussion in 'Questions (Windows Mobile)' started by tcgoh, Dec 24, 2007.

  1. tcgoh

    tcgoh Active Member Licensed User

    Hi Erel,

    I am trying out this this SQL expression

    SUB btnExecute_click
    cmd.CommandText=" SELECT DISTINCT NAME, RANK, CODE FROM CUSTS ORDER BY NAME"
    cmd.ExecuteTable("table1",0)
    cmd.CommandText=" SELECT DISTINCT DUTY, DATE1, TIME, FLTNO, DATE2 FROM CUSTS WHERE NAME='JOHN' ORDER BY DATE1"
    cmd.ExecuteTable("table2",0)
    end sub

    From the WHERE NAME='JOHN', how could I replace 'JOHN' form a textbox.text?

    Thanks
    TC
     
  2. BjornF

    BjornF Active Member Licensed User

    Dear TC,

    Have a look at the demo-program by Giannimaione (thread http://www.basic4ppc.com/forum/showthread.php?t=310&highlight=demosql)

    It is a very short program but it contains many useful hints, amongst them the answer to your question.

    all the best,

    Björn

    *****************************

    quote=CHR(39)

    Sub Button1_Click
    'insert data
    MyData1=quote & "ALFA" & quote
    'or MyData1=quote & textbox.Text & quote
    MyData2=Quote & "BETA" & quote

    text="insert into NameTable (Field1, Field2) values ("
    text=text & MyData1 & "," & MyData2 & ")"
    Msgbox(text)
    cmd.CommandText=text
    cmd.ExecuteNonQuery
    End Sub
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Try:
    Code:
    cmd.CommandText="... WHERE NAME = '" & textbox.text & "' ORDER ..."
     
  4. tcgoh

    tcgoh Active Member Licensed User

    Got it!

    Thanks Erel.
     
  5. tcgoh

    tcgoh Active Member Licensed User

    Hi AnyOne with SQL knowledge,

    1st of all thanks for all the help, now I'm learning to program SQL slowly.

    I have a problem now with WHERE statement:

    If WHERE = ' name with a' in between' How do I go around with this ' problem?

    Thanks
     
  6. dzt

    dzt Active Member Licensed User

    Add one more ' beside the one that exists
     
  7. tcgoh

    tcgoh Active Member Licensed User

    Thanks! But what if the database comes with names which have ' ?

    How do I filter out these names?

    Thanks n Happy New year.
     
  8. dzt

    dzt Active Member Licensed User

    You should search for it and replace it

    StrReplace
    ("name", "'", "''")
     
Loading...