vendredi 18 décembre 2015

select data sqlite from input c++

i have a problem here but i dont know how to fix it.. here is my code

void anggota()
{

int idanggota;
char nama[90];
char jenisKelamin[90];
char fakultas[90];
char alamat[90];
char programStudi[90];
char telepon[90];
int input;
cout<<"1.input data anggota\n";
cout<<"2.lihat data anggota\n";
cin>>input;
if(input==1)
    {
        cout<<"Anggota : ";cin>>idanggota;
        cout<<"nama : ";cin>>nama;
        cout<<"jenis kelamin : ";cin>>jenisKelamin;
        cout<<"fakultas : ";cin>>fakultas;
        cout<<"program studi : ";cin>>programStudi;
        cout<<"alamat : ";cin>>alamat;
        cout<<"telepon : ";cin>>telepon;
        char szSQL[]="INSERT INTO anggota(idAnggota,nama,jeniskelamin,fakultas,programstudi,alamat,telepon) VALUES (?,?,?,?,?,?,?);";
        rc=sqlite3_prepare_v2(db,szSQL,900,&ppStmt,0);
        sqlite3_bind_int(ppStmt,1,idanggota);
        sqlite3_bind_text(ppStmt,2,nama,-1,0);
        sqlite3_bind_text(ppStmt,3,jenisKelamin,-1,0);
        sqlite3_bind_text(ppStmt,4,fakultas,-1,0);
        sqlite3_bind_text(ppStmt,5,programStudi,-1,0);
        sqlite3_bind_text(ppStmt,6,alamat,-1,0);
        sqlite3_bind_text(ppStmt,7,telepon,-1,0);
        rc=sqlite3_step(ppStmt);
        if(rc!=SQLITE_DONE)
        {
            sqlite3_busy_handler(db,NULL,0);
            cout<<"gagal !!\n";
            cout<<sqlite3_errmsg(db);
        }
    }
else
{
    cout<<"Masukan id anggota :";
    cin>>idanggota;
    string select="select idAnggota from anggota where idAnggota=?";
    rc=sqlite3_prepare_v2(db,select.c_str(),500,&ppStmt,0);
    if(rc==SQLITE_OK)
    {


        sqlite3_bind_int(ppStmt,1,idanggota);
    }
    else
    {
        cout<<sqlite3_errmsg(db)<<":"<<sqlite3_errcode(db)<<endl;
    }
    rc=sqlite3_step(ppStmt);   
    if(rc==SQLITE_ROW)
    {          
        cout<<sqlite3_column_text(ppStmt,0)<<endl;
        cout<<sqlite3_column_text(ppStmt,1)<<endl;
        cout<<sqlite3_column_text(ppStmt,2)<<endl;
        cout<<sqlite3_column_text(ppStmt,3)<<endl;
        cout<<sqlite3_column_text(ppStmt,4)<<endl;
        cout<<sqlite3_column_text(ppStmt,5)<<endl;
        cout<<sqlite3_column_text(ppStmt,6)<<endl; 
    }

}
sqlite3_finalize(ppStmt);

 }

my program doesn't return an error but it isn't showing the data that i selected from database..

i have already googled it and still not fixing my program..

thanks for read

Aucun commentaire:

Enregistrer un commentaire