Android Question Insert Data to SqlLite from EditText

Discussion in 'Android Questions' started by D074, Jul 13, 2015.

  1. D074

    D074 New Member

    Hello,

    please help me,

    I dont know why my code error pause in this line code :

    s.ExecNonQuery2("INSERT INTO identitas VALUES(?, ?, ?, ?)", Array As String(" "txtNama.Text &" "," "& txtAlamat.Text &" "," "& txtUsername.Text &" "," "& txtPassword.Text &" "))

    but when I change the line code to be :

    s.ExecNonQuery2("INSERT INTO identitas VALUES(?, ?, ?, ?)", Array As String("'"txtNama.Text &"'","'"& txtAlamat.Text &"'","'"& txtUsername.Text &"'","'"& txtPassword.Text &"'"))

    it works, but store the sign ('), while I dont want the sign saved include the value of text. please help me.
     
  2. DonManfred

    DonManfred Expert Licensed User

    Try it like this
    Code:
    s.ExecNonQuery2("INSERT INTO identitas VALUES(?, ?, ?, ?)"Array As String(txtNama.Text,txtAlamat.Text,txtUsername.Text,txtPassword.Text))
     
    mangojack and Erel like this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    @DonManfred code will work properly. You do not need to escape or quote strings when you use parameterized queries (this is one of the advantages).
     
  4. D074

    D074 New Member

    Thanks, it works.
     
Loading...