如何在Microsoft Visual C 2010 Express项目中创建本地数据库?
|
如何在Microsoft Visual C 2010 Express项目中创建本地数据库?
对不起,我在网上找不到这个简单的答案.我找到的唯一答案是Visual Studio:使用项目>添加新项目>本地数据库.但是此选项在Visual c 2010 Express版中不可用. 我尝试安装“Microsoft SQL Server Compact 4”和“Microsoft SQL Server Denali”,并从“Windows Update”更新“Microsoft Visual C 2010 Express”.
好的,我终于得到了解决方案.遗憾的是,我必须回答我自己的问题……
我使用了SQLite库(http://www.sqlite.org/).这有点复杂,因为sqlite文档有点模糊,但我做了如下:
然后,很容易使用禁止查询,但是如果你想使用SQL“SELECT”,你可以使用这个代码: 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);
// Insert first row and second row
queries = "INSERT INTO users VALUES('manish','manish',1)";
retval = sqlite3_exec(handle,queries.c_str(),0);
queries = "INSERT INTO users VALUES('mehul','pulsar',0)";
retval = sqlite3_exec(handle,0);
// select those rows from the table
queries = "SELECT * from users";
retval = sqlite3_prepare_v2(handle,-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);
我希望这些信息有用! 资料来源: > http://www.gamedev.net/topic/332251-sqlite3-and-visual-c/page_p_3157685#entry3157685 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 如何在Windows上的C和PHP之间进行通信?
- 使用非标准端口在Windows上通过SSH设置Git
- Windows编译Nginx源码
- windows-server-2003 – 将Windows 7 64位打印驱动程序添加
- 是否有用于Windows(或Linux)的iPhone模拟器来安装iPhone应用
- 如何从SVG文件批量创建Windows中的图标webfonts
- Windows – Tomcat 7的service.bat文件丢失
- 在Windows上使用音频检测进程
- windows – 有没有办法使用GroupPolicy设置对WMI的访问?
- 如何在Windows 10上禁用新的Hyper-V VM的“使用自动检查点”
