Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

reading a bit sql column value using crecordset

$
0
0

Hi all,

I'm using Visual Studio 2010 to write some vc++ code. There is some code that I had written and its not working. I'v a method that reads string values from the crecordset just fine, but then I want to read a value which is in Bit type sql column.

The code that works is this:

copyval(datatable, "D_TestNumber", st->d_testnumber);
copyval(datatable, "D_TestName", st->d_testname);
copyval(datatable, "R_TestNumber", st->r_testnumber);


function defined as this:

void copyval(CRecordset & rs, char * fieldname, char* destfield)
{
CString tmp = "";
rs.GetFieldValue (fieldname, tmp);
char * tmpptr = tmp.GetBuffer (tmp.GetLength ());
strcpy (destfield, tmpptr);
tmp.ReleaseBuffer ();

}


Now I want to read the bit field, for which I made:

void copyval_b(CRecordset & rs, char * fieldname)
{
CDBVariant tmp;
rs.GetFieldValue (fieldname, tmp, SQL_BIT); // <<< error statement
BYTE b = tmp.m_boolVal;

}


on rs.GetFieldValue I get an exception: "Invalid Descriptor Index". 

The recordset was opened as: CRecordset::forwardOnly, it was opened as snapshot before but then I changed to forward only cuz nothing seems to be working. Please guide me so that I can solve this problem. I'm unable to read int sql types as well as the bit type, its really confusing.

thanks.

..ab

PS: I'm sorry if i'm posting to the wrong forum, its such a pain to select the correct forum here, I was hoping there would be something easily selected forum where I can post MFC and Database programming related stuff in C++, i'v no idea now so i'm ust posting to VC++ group.


Ab


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>