Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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;
 }
 
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 4-Mar-13 23:19pm
Edited 5-Mar-13 1:40am
v3
Comments
phil.o at 5-Mar-13 9:02am
   
Please stop pushing some junk solutions ; this is not the way this forum works.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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".
  Permalink  
Comments
Faytix at 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.
Faytix at 5-Mar-13 8:24am
   
The part you mean works but i want to show thoose created tables in my dialog.
Richard MacCutchan at 5-Mar-13 9:40am
   
Then use the appropriate ListView messages to add the data, as described in the documentation.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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 Big Grin | :-D
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 5 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100