Click here to Skip to main content
15,922,696 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: function returning CRecordset Pin
David Crow6-May-05 10:02
David Crow6-May-05 10:02 
GeneralRe: function returning CRecordset Pin
scoroop6-May-05 15:31
scoroop6-May-05 15:31 
GeneralRe: function returning CRecordset Pin
David Crow6-May-05 16:33
David Crow6-May-05 16:33 
GeneralRe: function returning CRecordset Pin
scoroop7-May-05 0:34
scoroop7-May-05 0:34 
GeneralRe: function returning CRecordset Pin
David Crow7-May-05 7:59
David Crow7-May-05 7:59 
GeneralRe: function returning CRecordset Pin
scoroop7-May-05 8:20
scoroop7-May-05 8:20 
GeneralRe: function returning CRecordset Pin
David Crow7-May-05 10:47
David Crow7-May-05 10:47 
GeneralRe: function returning CRecordset Pin
scoroop7-May-05 11:28
scoroop7-May-05 11:28 
the other class is a window (dialog) class so there's nothing special. i click a button. it launches OnClickedButton function which calls my function Query(...) which is supposed to return recordset. then i want to browse it, extract necessary data and put it into listbox. and that's all. so the code i provided is almost complete. but i'll try to give you some more...

<br />
CRecordset* CDB::Query(CString path, CString SQLstring)<br />
{<br />
CDatabase db;<br />
CString driver,dsn;<br />
		<br />
driver = GetDriver(); //another function from this class<br />
<br />
dsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s", driver, path);<br />
<br />
TRY <br />
{<br />
db.Open(NULL, false, false, dsn);<br />
CRecordset* recset = new CRecordset(&db);<br />
recset->Open(CRecordset::forwardOnly, SQLstring, CRecordset::readOnly);<br />
return recset; <br />
//db.Close();  was here but isn;t any more according to your suggestion <br />
}<br />
CATCH(CDBException, dbex)<br />
{<br />
AfxMessageBox("Error: " + dbex->m_strError);<br />
}<br />
END_CATCH;<br />
}<br />


and then in OnClickedButton

<br />
void CBaseWindow::OnClickedButton1()<br />
{<br />
... // code which gives me path and sqlstring, it's ok for sure<br />
CString val;<br />
CDB d;<br />
CRecordset *recset = d.Query(path,sqlstring);<br />
<br />
// everything below is undoable because of "debug assertion failed" error. what i figured out is that recset is not opened :/... but opening it requires stuff like sql string so it makes no sense :/<br />
<br />
short fields = recset->GetODBCFieldCount();<br />
while(!recset.IsEOF())<br />
{<br />
   for(short i=0;i<fields;i++)<br />
   {<br />
      recset->GetFieldValue(i,val);<br />
      // i do something with val... <br />
   }<br />
   recset->MoveNext();<br />
}<br />
}<br />

that's the whole story...
GeneralRe: function returning CRecordset Pin
David Crow9-May-05 2:17
David Crow9-May-05 2:17 
GeneralRe: function returning CRecordset Pin
scoroop9-May-05 5:49
scoroop9-May-05 5:49 
Generalpassing a callback function pointer to a DLL within an MFC application Pin
DKaiser6-May-05 6:47
DKaiser6-May-05 6:47 
GeneralRe: passing a callback function pointer to a DLL within an MFC application Pin
Chris Losinger6-May-05 7:45
professionalChris Losinger6-May-05 7:45 
GeneralSecurity Template Pin
arthivjii6-May-05 6:45
arthivjii6-May-05 6:45 
GeneralMoving Items in a virtual List-View Pin
Luy6-May-05 5:38
Luy6-May-05 5:38 
Questionhow to embed a dialog into the frame? Pin
steven_wong6-May-05 4:19
steven_wong6-May-05 4:19 
GeneralTexture mapping and color replacing with GDI Pin
DaViL836-May-05 3:40
DaViL836-May-05 3:40 
Generalown class Pin
_tasleem6-May-05 2:36
_tasleem6-May-05 2:36 
GeneralRe: own class Pin
benjymous6-May-05 2:42
benjymous6-May-05 2:42 
GeneralRe: own class Pin
_tasleem6-May-05 3:29
_tasleem6-May-05 3:29 
GeneralRe: own class Pin
benjymous6-May-05 3:32
benjymous6-May-05 3:32 
GeneralRe: own class Pin
_tasleem6-May-05 4:15
_tasleem6-May-05 4:15 
GeneralRe: own class Pin
_tasleem6-May-05 21:21
_tasleem6-May-05 21:21 
GeneralRe: own class Pin
ThatsAlok6-May-05 2:43
ThatsAlok6-May-05 2:43 
GeneralRe: own class Pin
David Crow6-May-05 3:48
David Crow6-May-05 3:48 
GeneralRe: own class Pin
ThatsAlok6-May-05 20:59
ThatsAlok6-May-05 20:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.