c ++中的SQLite数据库 [英] SQLite Database in c++

查看:82
本文介绍了c ++中的SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我需要一些帮助,让桌子上班。



Hello there,
I need a little bit of help by getting a table to work.

BOOL CPrakt04Dlg::OnInitDialog()
{
    CDialog::OnInitDialog();

   
    SetIcon(m_hIcon, TRUE);         
    SetIcon(m_hIcon, FALSE);        

    
    Tabelle.InsertColumn(0,_T("Number"),LVCFMT_LEFT,35);
    Tabelle.InsertColumn(1, _T("Name"), LVCFMT_CENTER, 60);
    Tabelle.InsertColumn(2, _T("Age"), LVCFMT_LEFT,25);
    Tabelle.InsertColumn(3, _T("Score"), LVCFMT_LEFT, 70);

    int nItem;
    nItem = Tabelle.InsertItem(0, _T("1"));
    Tabelle.SetItemText(nItem, 1, _T("Brith"));
    Tabelle.SetItemText(nItem, 2, _T("54"));
    Tabelle.SetItemText(nItem, 3, _T("89"));

    nItem = Tabelle.InsertItem(0, _T("2"));
    Tabelle.SetItemText(nItem, 1, _T("Louis"));
    Tabelle.SetItemText(nItem, 2, _T("50"));
    Tabelle.SetItemText(nItem, 3, _T("110"));

    nItem = Tabelle.InsertItem(0, _T("3"));
    Tabelle.SetItemText(nItem, 1, _T("Magret"));
    Tabelle.SetItemText(nItem, 2, _T("12"));
    Tabelle.SetItemText(nItem, 3, _T("38"));

    nItem = Tabelle.InsertItem(0, _T("4"));
    Tabelle.SetItemText(nItem, 1, _T("Martin"));
    Tabelle.SetItemText(nItem, 2, _T("30"));
    Tabelle.SetItemText(nItem, 3, _T("70"));

// I need to get the inserted table here ._.
    
    return TRUE; 
}

#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CPrakt04Dlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
    if (AfxIsDRAEnabled())
    {
        DRA::RelayoutDialog(
            AfxGetResourceHandle(), 
            this->m_hWnd, 
            DRA::GetDisplayMode() != DRA::Portrait ? 
            MAKEINTRESOURCE(IDD_PRAKT04_DIALOG_WIDE) : 
            MAKEINTRESOURCE(IDD_PRAKT04_DIALOG));
    }
}
#endif



 void CPrakt04Dlg::OnBnClickedBnTbe()
 {
    int error;
    sqlite3 *database;
    error=sqlite3_open("Database01.db3", &database);
    sqlite3_stmt *statement;
    error=sqlite3_prepare(database, "CREATE TABLE example (number INTEGER,name TEXT,age INTEGER,score INTEGER);", -1, &statement, 0);
    error=sqlite3_step(statement);
    error=sqlite3_exec(database,"insert into example values (5,'david',20,8);",NULL,NULL,NULL);
    error=sqlite3_finalize(statement);  
    error=sqlite3_close(database);

 }



 void CPrakt04Dlg::OnLvnItemchangedTb(NMHDR *pNMHDR, LRESULT *pResult)
 {
     LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

    
    *pResult = 0;
 }





这是我的代码,直到现在,我需要帮助,所以我可以看到插入exampe值(5 '' 大卫 '',20,8);在我的ListCtrl。



This is my code until now, i need help so i can see the "insert into exampe values (5,''david'',20,8);" in my ListCtrl.

推荐答案

您需要检查函数中的所有错误返回值。除此之外,你创建一个名为example的表,然后尝试插入一个名为exampe的表。
You need to check all of the "error" return values from the functions. Apart from that, you create a table called "example", then try to insert into a table called "exampe".


int nNumber;
	CString szName;
	int nAge;
	int nScore;
	sqlite3_open("Database03.db3", &database);
	sqlite3_prepare(database, "SELECT * FROM example;"), -1, &statement, 0);
	sqlite3_step(statement);



然后给它们值并将它们添加到你的表中:D


and then give them values and add them your table :D


这篇关于c ++中的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆