Home > Software engineering >  MFC ADO database problems
MFC ADO database problems

Time:10-04

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//can work: create a database
//entered: tmCurrent time
//output:
//back to back: TRUE success
//FALSE failure
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
BOOL CLog: : CreateDataBase (CTime * tmCurrent)
{
if(! TmCurrent) return FALSE.

CloseDataBase ();
Char DataBaseName [MAX_PATH];//CEP1: DataBaseName [100]
Char PathBaseName [MAX_PATH];//CEP1: PathBaseName [100]

//CReportDlg * pDlg=(CReportDlg *) AfxGetMainWnd ();

Sprintf (PathBaseName, % s \ \ "Log", dirWork);
: : CreateDirectory (PathBaseName, NULL);
Sprintf (DataBaseName, "% s \ \ Log \ \ Log 04 02 d % d % % 02 d. MDB", dirWork, tmCurrent - & gt; GetYear (), tmCurrent - & gt; TmCurrent, GetMonth () - & gt; GetDay ());
Cstrings strConnect;
StrConnect. The Format (_T (" Provider=Microsoft. Jet. The OLEDB. 4.0; Data Source=% s "), DataBaseName);
COleVariant Connect (strConnect);

Try
{
ADOX: : _CatalogPtr pCatalog=NULL;
PCatalog. CreateInstance (_T (" ADOX. Catalog "));
PCatalog - & gt; Create (LPCTSTR strConnect);
//to throw an exception here, creating a connection database, strives for the great god give directions!
PConnection. CreateInstance (_T (" ADODB. Connection "));
PConnection - & gt; PutCommandTimeout (30);
PConnection - & gt; PutConnectionTimeout (30);
PConnection - & gt; Put_CursorLocation (ADODB: : adUseClient);
PConnection - & gt; Open (_bstr_t (strConnect), _bstr_t (), _bstr_t (), ADODB: : adConnectUnspecified);
PCatalog - & gt; PConnection PutActiveConnection (_variant_t ((IDispatch *)));

ADOX: : _TablePtr pTableRadar=NULL;
PTableRadar. CreateInstance (_T (" ADOX. Table "));
PTableRadar - & gt; ParentCatalog=pCatalog;
PTableRadar - & gt; Name="radar log";
ADOX: : ColumnsPtr pColsRadar=pTableRadar - & gt; The Columns;
//pColsRadar - & gt; Append (_T (the original file name "time"), and ADOX: : adDate, 0).
PColsRadar - & gt; Append (_T (" the original file name "), and ADOX: : adWChar, 0).
PColsRadar - & gt; Append (_T (" compressed file name "), and ADOX: : adWChar, 128);
//pColsRadar - & gt; Append (_T (" compressed time "), and ADOX: : adDate, 0).
PColsRadar - & gt; Append (_T (" file send time "), ADOX: : adDate, 0).
PColsRadar - & gt; Append (_T (" upload success "), and ADOX: : adWChar, 0).

//pColsRadar - & gt; The GetItem (_T (the original file name "time")) - & gt; The Properties - & gt; The GetItem (_T (" Jet OLEDB: Compressed UniCode Strings ")) - & gt; Value=https://bbs.csdn.net/topics/true;
PColsRadar - & gt; The GetItem (_T (" the original file name ")) - & gt; The Properties - & gt; The GetItem (_T (" Jet OLEDB: Compressed UniCode Strings ")) - & gt; Value=https://bbs.csdn.net/topics/true;
PColsRadar - & gt; The GetItem (_T (" compressed file name ")) - & gt; The Properties - & gt; The GetItem (_T (" Jet OLEDB: Compressed UniCode Strings ")) - & gt; Value=https://bbs.csdn.net/topics/true;
//pColsRadar - & gt; The GetItem (_T (" compressed time ")) - & gt; The Properties - & gt; The GetItem (_T (" Jet OLEDB: Compressed UniCode Strings ")) - & gt; Value=https://bbs.csdn.net/topics/true;
PColsRadar - & gt; The GetItem (_T (" file send time ")) - & gt; The Properties - & gt; The GetItem (_T (" Jet OLEDB: Compressed UniCode Strings ")) - & gt; Value=https://bbs.csdn.net/topics/true;
PColsRadar - & gt; The GetItem (_T (" upload success ")) - & gt; The Properties - & gt; The GetItem (_T (" Jet OLEDB: Compressed UniCode Strings ")) - & gt; Value=https://bbs.csdn.net/topics/true;

PCatalog - & gt; Tables - & gt; Append (_variant_t (pTableRadar (IDispatch *)));

ADOX: : _TablePtr pTableNote=NULL;
PTableNote. CreateInstance (_T (" ADOX. Table "));
PTableNote - & gt; ParentCatalog=pCatalog;
PTableNote - & gt; Name="terminal diary";
ADOX: : ColumnsPtr pColsNote=pTableNote - & gt; The Columns;
PColsNote - & gt; Append (_T (" content "), and ADOX: : adWChar, 255);
PColsNote - & gt; The GetItem (_T (" content ")) - & gt; The Properties - & gt; The GetItem (_T (" Jet OLEDB: Compressed UniCode Strings ")) - & gt; Value=https://bbs.csdn.net/topics/true;
PCatalog - & gt; Tables - & gt; Append (_variant_t (pTableNote (IDispatch *)));

PCatalog - & gt; Tables - & gt; The Refresh ();
TmOpened=* tmCurrent;
BOpened=TRUE;
}
The catch (_com_error & amp; E)
{
Return FALSE;
}
The catch (... )
{
Return FALSE;
}

return TRUE;
}
//CreateDataBase end ()
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CodePudding user response:

DataBaseName breakpoint debugging to see if this path to the corresponding file exists

CodePudding user response:

PCatalog - & gt; Create (LPCTSTR strConnect);

This should use
PCatalog - & gt; Create (_bstr strConnect);
  • Related