Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there,
I need a little bit of help by getting a table to work.

C++
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;
 }


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.
Posted
Updated 19-Mar-22 4:59am
v3
Comments
phil.o 5-Mar-13 9:02am    
Please stop pushing some junk solutions ; this is not the way this forum works.

C++
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);

and then give them values and add them your table :D
 
Share this answer
 
v2
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".
 
Share this answer
 
Comments
[no name] 5-Mar-13 6:30am    
I have a List Control on my dialog and i want to set the tables there automatic with the ones from the sql.
[no name] 5-Mar-13 8:24am    
The part you mean works but i want to show thoose created tables in my dialog.
Richard MacCutchan 5-Mar-13 9:40am    
Then use the appropriate ListView messages to add the data, as described in the documentation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900