samedi 5 septembre 2015

error in using insert query in android

I am saving some data and pic to my db I found out the true way to save my pic in db is to use contentvalue so this the code:

                try 
                {

                    MyDataBase = new MyDatabase(this);
                    mydb = MyDataBase.getWritableDatabase();
                    ContentValues tempval;
                    for (int j = 0; j < myarray.arrtitle.length; j++)
                    {
                        tempval = saveimage(myarray.arrpic.get(j),myarray.arrpath[j]);
                        mydb.execSQL("INSERT INTO news (title,content) VALUES  (\"" + myarray.arrtitle[j] +
                        "\",\"" + myarray.arrcontent[j] + "\"" + ")");
                        mydb.insert("news", null, tempval);
                    }
                    mydb.close();
                    Toast.makeText(getApplicationContext(), "database 2 done", Toast.LENGTH_LONG).show();
                    count = 5;
                } catch (Exception e) {
                    // TODO: daabase error2
                    Toast.makeText(getApplicationContext(), "data error2", Toast.LENGTH_LONG).show();
                }

so this is how i can save my data correctly. but the problem is when I insert my image, it insert in new row not the row as same as title was inserted. is there any way to handle this?

Aucun commentaire:

Enregistrer un commentaire