Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have a MS Access DB file ("Notice.mdb") which has 29 columns & 20 rows of strings data of Memo datatype.

I need a code snippet in VC++ using which i can retrieve the strings and store it in some CString array.

Please help

Thanks & regards
Dinesh
Posted

1 solution

#include "afxdao.h"

CString lpszFile = L"MyTables.mdb";
CDaoDatabase db;
db.Create(lpszFile);
db.Open(lpszFile);

db.Execute(L"CREATE TABLE MyTable (Field1 VARCHAR(20), Field2 VARCHAR(20));");

db.Execute(L"INSERT INTO MyTable(Field1, Field2) VALUES ('value11', 'value12');");
db.Execute(L"INSERT INTO MyTable(Field1, Field2) VALUES ('value21', 'value22');");

CDaoRecordset recordset(&db);

recordset.Open(AFX_DAO_USE_DEFAULT_TYPE, L"SELECT * FROM MyTable;", 0);

COleVariant olevarValue1;
COleVariant olevarValue2;

while(!recordset.IsEOF())
{
olevarValue1.ChangeType(VT_BSTR, NULL);
olevarValue2.ChangeType(VT_BSTR, NULL);
recordset.GetFieldValue(L"Field1", olevarValue1);
recordset.GetFieldValue(L"Field2", olevarValue2);
printf("Value1: %s\n", (LPCTSTR)olevarValue1.bstrVal);
printf("Value2: %s\n", (LPCTSTR)olevarValue2.bstrVal);
recordset.MoveNext();
}
 
Share this answer
 

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