Android Question Error in parameter Sql query

Discussion in 'Android Questions' started by omidaghakhani1368, Jul 5, 2015.

  1. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi.
    I use below code for get row count but get error
    sql1.ExecQuerySingleResult2("SELECT COUNT(*) FROM tbl_friends WHERE sID ='?'",Array As String(user_id)) = 0 Then

    error : android.database.sqlite.SQLiteBindOrColumnIndexOutOfRangeException: bind or column index out of range: handle 0x149eb8
     
  2. Pendrush

    Pendrush Active Member Licensed User

    Code:
    sql1.ExecQuerySingleResult2("SELECT COUNT(*) FROM tbl_friends WHERE sID=?",Array As String(user_id)) = 0 Then
    remove ' before and after ?
     
  3. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Thank you but my string dont have a quote.are you sure?
     
  4. mangojack

    mangojack Well-Known Member Licensed User

    maybe
    Code:
    Dim rowCount As Int = sql1.ExecQuerySingleResult2("SELECT COUNT(*) FROM tbl_friends WHERE sID=?",Array As String(user_id))
    If rowCount = 0 Then
     
  5. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Thank you,i test it but get error.it is wonderfull
     
  6. sorex

    sorex Expert Licensed User

    IDs are numbers most of the time then you don't need to use quotes
     
  7. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    I know.Number field in my table is type of TEXT and i according field type decide to use quote
     
  8. sorex

    sorex Expert Licensed User

    I'm not 100% sure about SQLite but I believe it's always text but it detects on the content if it is a number, date, datetime or real string field.
     
  9. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    use quote according to field's type In all databases(mssql,mysql,sqlite and ...) is same.
    just when use prepare parameter in b4a is problem
     
  10. sorex

    sorex Expert Licensed User

    with the exeption that SQLite only has text field types even when you select date or anything else in an sqlite editor.
     
  11. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    let me to export project and attachment here
     
Loading...