· 8 years ago · Apr 09, 2018, 01:54 AM
1column 'quantidade' does not exist
2
3private static String nomebanco = "bancoma.db";
4public static String tabela = "pedidoitens";
5public static String id = "_id";
6public static String item = "item";
7public static String quantidade = "quantidade";
8public static String valorunitario = "valorunitario";
9private static int versao = 1;
10
11public BancoInterno(Context context) {
12 super(context, nomebanco, null, versao, null);
13}
14
15@Override
16public void onCreate(SQLiteDatabase db) {
17 String sql = "CREATE TABLE "+tabela+"( "
18 +id+" integer primary key autoincrement, "
19 +item+" text(200), "
20 +quantidade+" integer(3), "
21 +valorunitario+" real(3,2)"
22 +")";
23 db.execSQL(sql);
24}
25
26@Override
27public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
28 db.execSQL("DROP TABLE IF EXISTS "+tabela);
29 onCreate(db);
30}
31
32private SQLiteDatabase db;
33private BancoInterno banco;
34
35public BancoControlador(Context context){
36 banco = new BancoInterno(context);
37}
38
39public String InserirDados(String item, int quantidade, double valorunitario){
40
41 ContentValues valores;
42 long resultado;
43
44 db = banco.getWritableDatabase(); // Criar banco para inserção
45 valores = new ContentValues(); // Instancia os valores
46
47 valores.put(BancoInterno.item, item); // Inserindo..
48 valores.put(BancoInterno.quantidade, quantidade);
49 valores.put(BancoInterno.valorunitario, valorunitario);
50
51 resultado = db.insert(BancoInterno.tabela, null, valores);
52
53 if(resultado==-1)
54 {
55 return "Erro para gravar os dados";
56 }
57 else {
58 return "Gravado com sucesso";
59 }
60}
61
62public Cursor carregaDados(){ //Sem Where
63 Cursor cursor;
64 String[] campos = {banco.id,banco.item};
65 db = banco.getReadableDatabase();
66
67 cursor = db.query(banco.tabela, campos, null, null, null, null, null);
68
69 return cursor;
70}
71
72control = new BancoControlador(getApplicationContext());
73 cursor = control.carregaDados();
74 while(cursor.moveToNext())
75 {
76 String produto = cursor.getString(cursor.getColumnIndexOrThrow("item"));
77 int quantidade = cursor.getInt(cursor.getColumnIndexOrThrow("quantidade"));
78 //String valorunitario = cursor.getString(cursor.getColumnIndexOrThrow("valorunitario"));
79 Toast.makeText(getApplicationContext(), produto+" ", Toast.LENGTH_LONG).show();
80 }