Ok, cuối cùng tôi đã nhận được giải pháp. Đáng tiếc tôi phải trả lời câu hỏi của riêng tôi ...
Tôi đã sử dụng thư viện SQLite (http://www.sqlite.org/). Đó là một chút phức tạp bởi vì các tài liệu SQLite là một chút mơ hồ, nhưng tôi đã làm như sau:
- Tải sqlitedll * .zip - trích xuất .def và các file .dll ở đâu đó.
- Tạo tệp lib bằng lệnh như "c: \ program files \ micros ~ 1 \ vc98 \ bin \ lib" /def:sqlite3.def ". Làm điều đó từ dấu nhắc lệnh , trong thư mục có Bạn có thể cần phải chạy vcvars32.bat đầu tiên, đó là cũng trong thư mục bin. Sao chép kết quả .lib đến một địa chỉ thích hợp và đặt thư mục thư viện trong VC++. (Hoặc thực hiện trên cơ sở mỗi dự án.)
- Tải xuống tệp * .zip sqlite nguồn và giải nén tệp sqlite3.h từ trong thư mục phù hợp. một thư mục bao gồm trong VC++. (Một lần nữa, bạn có thể làm điều đó trên cơ sở từng dự án.)
- Trong dự án của bạn, #include theo yêu cầu, thêm sqlite3.lib vào dự án của bạn, sao chép sqlite3.dll vào thư mục thi hành của bạn hoặc thư mục làm việc và bạn nên sẵn sàng để đi.
Sau đó, rất dễ sử dụng không ra thắc mắc, nhưng nếu bạn muốn sử dụng một SQL "SELECT" ví dụ, bạn có thể sử dụng mã này:
std::string queries;
// A prepered statement for fetching tables
sqlite3_stmt *stmt;
// Create a handle for database connection, create a pointer to sqlite3
sqlite3 *handle;
// try to create the database. If it doesnt exist, it would be created
// pass a pointer to the pointer to sqlite3, in short sqlite3**
int retval = sqlite3_open("local.db",&handle);
// If connection failed, handle returns NULL
if(retval){
System::Windows::Forms::MessageBox::Show("Database connection failed");
return;
}
// Create the SQL query for creating a table
char create_table[100] = "CREATE TABLE IF NOT EXISTS users (uname TEXT PRIMARY KEY,pass TEXT NOT NULL,activated INTEGER)";
// Execute the query for creating the table
retval = sqlite3_exec(handle,create_table,0,0,0);
// Insert first row and second row
queries = "INSERT INTO users VALUES('manish','manish',1)";
retval = sqlite3_exec(handle,queries.c_str(),0,0,0);
queries = "INSERT INTO users VALUES('mehul','pulsar',0)";
retval = sqlite3_exec(handle,queries.c_str(),0,0,0);
// select those rows from the table
queries = "SELECT * from users";
retval = sqlite3_prepare_v2(handle,queries.c_str(),-1,&stmt,0);
if(retval){
System::Windows::Forms::MessageBox::Show("Selecting data from DB Failed");
return ;
}
// Read the number of rows fetched
int cols = sqlite3_column_count(stmt);
while(1){
// fetch a row’s status
retval = sqlite3_step(stmt);
if(retval == SQLITE_ROW){
// SQLITE_ROW means fetched a row
// sqlite3_column_text returns a const void* , typecast it to const char*
for(int col=0 ; col<cols;col++){
const char *val = (const char*)sqlite3_column_text(stmt,col);
System::Windows::Forms::MessageBox::Show(stdstr2systemstr(sqlite3_column_name(stmt,col))+" = "+stdstr2systemstr(val));
}
}
else
if(retval == SQLITE_DONE){
// All rows finished
System::Windows::Forms::MessageBox::Show("All rows fetched");
break;
}
else{
// Some error encountered
System::Windows::Forms::MessageBox::Show("Some error encountered");
return ;
}
}
// Close the handle to free memory
sqlite3_close(handle);
Tôi hy vọng thông tin này có ích!
Nguồn:
MSVC sử dụng để có dự án dbase. Tất cả loại bỏ xung quanh VS2008, chỉ là về không ai viết mã dbase trong C + +. Không có nhiều người dùng nhận thấy, hỗ trợ IDE luôn thiếu. –