2. Use the DATAGRID must register a VC2010 and DATAGRID link way you can use the ODBC database, I baidu results we were using ADO.
The small white one, with enthusiastic predecessors to give directions,
CodePudding user response:
Connection field, is the main method of ODBC and operating SQL are almost
Void TestAccessDBData (LPCTSTR szFilePath, LPCTSTR szUID, LPCTSTR szPWD, LPCTSTR szTabName)
{
Try
{
//structure connected characters
Cstrings szConnect;
SzConnect. The Format (
_T (" Driver={Microsoft Access Driver (*. MDB)};" )
_T (DBQ=% s; "" )
_T (" UID=% s. The PWD=% s." ),
SzFilePath szUID, szPWD);
//open the database
CDatabase db;
If (db. OpenEx (szConnect, db noOdbcDialog | the useCursorLib))
{
//query
Try
{
Cstrings szCmd;
SzCmd. The Format (_T (" SELECT * FROM % s "), szTabName);
//here you can add additional WHERE conditions such as the WHERE ID='1234'
CRecordset rs (& amp; Db);
If (rs. Open (AFX_DB_USE_DEFAULT_TYPE szCmd, rs. ExecuteDirect))
{
while(! Rs. IsEOF ())
{
Cstrings sVal;
Rs. GetFieldValue (_T (" ID "), sVal);
TRACE (_T (" ID=% s \ n "), (LPCTSTR) sVal);
Rs. MoveNext ();
}
//close the query
Rs. The Close ();
}
}
The catch (CDBException * e)
{
E - & gt; ReportError ();
E - & gt; The Delete ();
}
//INSERT input (INSERT INTO)
Try
{
Cstrings szCmd;
SzCmd. The Format (_T (" INSERT INTO % s (ID, Name) VALUES (' 1234 ', 'test') "),
SzTabName);
The db. The ExecuteSQL (szCmd);
}
The catch (CDBException * e)
{
E - & gt; ReportError ();
E - & gt; The Delete ();
}
//close the database
The Close ();
}
}
The catch (CDBException * e)
{
E - & gt; ReportError ();
E - & gt; The Delete ();
}
}