0

I am getting this error While I am inserting data in table:

Error inserting NAME='ashish' ID='1' DEPT='computer ' ROLL NO='12' DIV='c'

android.database.sqlite.SQLiteException: near "NO": syntax error (code 1): , while compiling: INSERT INTO Personal_info(NAME,ID,DEPT,ROLL NO,DIV) VALUES (?,?,?,?,?)

And Inserting data lines are->

public void addData()
{
    ButtonAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean isInserted=myHelp.insertData("'"+EditID.getText().toString()+"'",
                                                 "'"+EditRoll.getText().toString()+"'",
                                                 "'"+EditName.getText().toString()+"'",
                                                 "'"+EditDept.getText().toString()+"'",
                                                 "'"+EditDiv.getText().toString()+"'");
            if (isInserted==true)
                Toast.makeText(MainActivity.this,"Data Inserted",Toast.LENGTH_LONG ).show();
            else
                Toast.makeText(MainActivity.this,"Data Not Inserted",Toast.LENGTH_LONG ).show();
             }
        });
    }
}



public boolean insertData(String ID,String Rollno, String Name, String Dept, String Div) {
    SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
    ContentValues contentValues=new ContentValues();
    contentValues.put(COL1,ID);
    contentValues.put(COL2,Rollno);
    contentValues.put(COL3,Name);
    contentValues.put(COL4,Dept);
    contentValues.put(COL5, Div);
    long result = sqLiteDatabase.insert(TABLE_NAME,null,contentValues);
    if(result==-1)
    return false;
    else
        return true;
}
4
  • Remove space between ROLL NO Commented Aug 13, 2016 at 7:40
  • is it solve error? Commented Aug 13, 2016 at 7:48
  • yes it solved the error. thanks alot Commented Aug 13, 2016 at 8:44
  • then accept answer it will help others Commented Aug 13, 2016 at 9:02

1 Answer 1

3

Remove space between ROLL NO it will solve you error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.