Home > Software engineering >  Ask a few questions: the combo box, the DATAGRID
Ask a few questions: the combo box, the DATAGRID

Time:09-21

1. To use VC2010 combo box link ACCESS database, ODBC, achieve the goal of the content of the data table according to the combo box in the drop-down list, in addition to the combo box input a new entry into the database automatically, consult how to implement, or is there a reference example, thank you.
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 ();
}
}

  • Related