How to use GetDlgItemText with Win32 ADO Recordsets ?

I've read through msdn pages, these article pages and the FAQ and of course none of them show me what I need. I just hope that doesn't mean its not possible. Anyway, here goes with the problem.

With the assistance of your site and the msdn site I have finally got to grips with the basics of the ADOX commands and then realised this is only useful for accessing and creating the schema. Sigh, so had to root around the ADO stuff that I haven't used in literally ages to access the data. But finally did it. Only took all weekend to figure it out. Haha. Using Visual C++ 6 Win32 code in case you were wondering.

So now I can create databases and tables (Access MDBs by the way) and using hard coded values add and retrieve records. So now I want to utilise dialog boxes to retrieve user input that will add or amend records in the recordsets in question. One problem though. I can convert from the variable type GetDlgItemText seems to insist on (TCHAR varname[25]) to what ADO uses to utilise strings (_bstr_t).

Now the ADO is AOK article by Bob Place was handy in that it helped me pinpoint some earlier bugs in my program but now I need to find out how to get the EDIT box values into my recordset fields and vice versa.

Variables to pass edit box contents to
TCHAR col1[25];
TCHAR col2[15];
TCHAR col3[15];
>> Note: tried char* LPTSTR etc so as to get rid of 25/15/15 values but no data is retrieved from the edit box for some reason.

Code exectuted when the OK button is pressed.
GetDlgItemText(hDlg,IDC_EDIT1,col1,25);
GetDlgItemText(hDlg,IDC_EDIT2,col2,15);
GetDlgItemText(hDlg,IDC_EDIT3,col3,15);

Code to retrieve data to edit.
Open MDB File, Open a Recordset with a SELECT statement.

// We now have a record available to retrieve data from and place in dialog vars
col1 = (char*)(_bstr_t(dbd.m_pRecordset->GetCollect("Col1")));
col2 = _bstr_t(dbd.m_pRecordset->GetCollect("Col2"));
col3 = _bstr_t(dbd.m_pRecordset->GetCollect("Col3"));
// This reports inability to convert char* to char or _bstr_t to char.

DisplayDialog and Initialise with retrieved data
Close Recordset and MDB File

I am almost at hair pulling stage after spending ages trying to figure out why this isn't working. What do I need to do to mesh the Dialog string values to the ADO string values in Win32 that is?

I heard that std::string is the Win32 alternative to CString but my app had a problem with the std:: part so will look into that when I next have a chance, which by the current time will be in about 20 hrs time what with sleep and work.

Thanks for any light you can shed on what no doubt will be so simple a solution I overlooked it. Haha

Xrystal
[2845 byte] By [Xrystal] at [2007-11-19 6:15:04]
# 1 Re: How to use GetDlgItemText with Win32 ADO Recordsets ?
I think your problems stem from the lack of understanding of the various string types available.

Have a look at http://www.hal-pc.org/~abeld/cppsighal/vcppstrings.htm
Bob Sheep at 2007-11-11 0:32:02 >
# 2 Re: How to use GetDlgItemText with Win32 ADO Recordsets ?
Thanks for any light you can shed on what no doubt will be so simple a solution I overlooked it. What I'm wondering is why you want to use ADO for accessing an mdb database? Since you seem to be using MFC, simply use CDatabase, CRecordset (or CDaoDatabase / CDaoRecordset). Then you won't need to do all that GetDialogItem() stuff manually, but use CRecordView() and benefit from record field exchange (RFX) to automatically transfer data between your database fields and controls.
gstercken at 2007-11-11 0:33:02 >
# 3 Re: How to use GetDlgItemText with Win32 ADO Recordsets ?
Yes the different strings confuse me. I usually stick to char, char* and TCHAR when it asks for it. This _bstr_t is new to me (first look at DB programming in years especially in C++) and I am getting to grips with how it works with the other string variables I usually use.

I have been coding non-MFC apps since almost day 1 (of getting VC6 although not everyday) with MFC only being used on examples downloaded from MSDN which end up being little help.

Anyway, managed to resolve my problem by doing the following:

_bstr_t Col1;
_bstr_t Col2;
_bstr_t Col3;
Col1 = _bstr_t(dbd.m_pRecordset->GetCollect("Col1"));
Col2 = _bstr_t(dbd.m_pRecordset->GetCollect("Col2"));
Col3 = _bstr_t(dbd.m_pRecordset->GetCollect("Col3"));
strcpy(tt2.col1,Col1);
strcpy(tt2.col2,Col2);
strcpy(tt2.col3,Col3);

To store db data into editbox variables and :

Col1 = strdup(tt2.col1);
Col2 = strdup(tt2.col2);
Col3 = strdup(tt2.col3);

To store editbox variables into db data variables.

I'm surprised I forgot about these as I usually mention these to my brother when he hits string problems. *slaps head*

Thanks for your assistance and have already bookmarked that site you mentioned. Will be handy in the future if I hit similar problems.

Xrystal
Xrystal at 2007-11-11 0:33:59 >