CADO 3
Assalamualaikum Waohmatullahi wabarakatuh
Langsung saja teman teman, berikut adalah contoh Class koneksi C++ dengan menggunakan database SQL Server.
CADO 3 file main() #include "ADO.h" #define DB_SERVER_IP "192.168.0.1" #define DB_NAME "MYDB" #define DB_USER_ID "admin" #define DB_USER_PW "password"
int main(int argc, char* argv[]) { int nTemp;
_RecordsetPtr rs = NULL; CADO myADO; if(!myADO.Connect(DB_SERVER_IP, DB_NAME, DB_USER_ID, DB_USER_PW)) printf("Fail to connect\n"); else printf("Connection success\n"); if(!myADO.SQLInsert("dbo.TEST", "4, 'babo'")) printf("Insert Fail\n"); else printf("Effected query successfully\n"); rs = myADO.SQLSelect("dbo.TEST"); if(rs==0) printf("Select Fail\n"); else nTemp = rs->GetCollect("nNum").intVal; // else // printf("Effected query successfully\n");
if(!myADO.SQLUpdate("dbo.TEST", "szString='nice'", "nNum=1")) printf("Update Fail\n"); else printf("Effected query successfully\n"); if(!myADO.SQLDelete("dbo.TEST", "nNum=5")) printf("Delete Fail\n"); else printf("Effected query successfully\n");
rs = (_Recordset*)myADO.SQLExcute("select * from dbo.TEST");
Langsung saja teman teman, berikut adalah contoh Class koneksi C++ dengan menggunakan database SQL Server.
CADO 3 file main() #include "ADO.h" #define DB_SERVER_IP "192.168.0.1" #define DB_NAME "MYDB" #define DB_USER_ID "admin" #define DB_USER_PW "password"
int main(int argc, char* argv[]) { int nTemp;
_RecordsetPtr rs = NULL; CADO myADO; if(!myADO.Connect(DB_SERVER_IP, DB_NAME, DB_USER_ID, DB_USER_PW)) printf("Fail to connect\n"); else printf("Connection success\n"); if(!myADO.SQLInsert("dbo.TEST", "4, 'babo'")) printf("Insert Fail\n"); else printf("Effected query successfully\n"); rs = myADO.SQLSelect("dbo.TEST"); if(rs==0) printf("Select Fail\n"); else nTemp = rs->GetCollect("nNum").intVal; // else // printf("Effected query successfully\n");
if(!myADO.SQLUpdate("dbo.TEST", "szString='nice'", "nNum=1")) printf("Update Fail\n"); else printf("Effected query successfully\n"); if(!myADO.SQLDelete("dbo.TEST", "nNum=5")) printf("Delete Fail\n"); else printf("Effected query successfully\n");
rs = (_Recordset*)myADO.SQLExcute("select * from dbo.TEST");
if(rs==0)
printf("Select Fail\n");
else
nTemp = rs->GetCollect("nNum").intVal;
// else
// printf("Effected query successfully\n");
if(!myADO.SQLExcute("Insert into dbo.TEST values(100,'lion')"))
printf("Insert Fail\n");
else
printf("Effected query successfully\n");
if(!myADO.DisConnect())
printf("Fail to disconnect\n");
else
printf("Disconnected\n");
return 0;
}
Terimakasih.
ReplyDeleteSangat membantu