It's more time to come to the 9CBS community, I chose some part from my own score, I think more representative sorting into a essence version, and I have a little bit of a little for VC / MFC version. Although the problem itself may have no representation, or it is not very helpful for some novice, but I think that there are some important topics, I hope to help everyone.
Q How to export the Excel table in the VC: SQL can be implemented: SQL can be implemented: SELECT * INTO MATERIAL IN 'C: / DB' 'Excel 8.0' from TBLMATERIAL Description: INTO's Material is the table name to import in the XLS file The back 'C: / DB' is your brigade XLS file. Excel 8.0 is the database format to be exported to export it to DBASE IV. You can export DBF file TBLMATERIAL is the table name import data to be exported in the MDB database: Reference VB function: http://search.9cbs.net/expert/ TOPIC / 828 / 828974.XML? Temp = .6185572
How to obtain Q ADO A_variant_t vFieldValue table name of the database table; CString strFieldValue; m_pRs = m_pConnection-> OpenSchema (adSchemaTables); while (VARIANT_FALSE == m_pRs-> IsEOF) {strFieldValue = (char *) _ bstr_t (m_pRs-> GetCollect ( "Table_Type")); if (! Strcmp (strcmp (strcmp) | | ") ||! Strcmp (StrfieldValue.getBuffer (0)," Table ")) {strfieldValue.releaseBuffer (); strfieldValue = (char *) _BSTR_T (M_PRS-> getCollect ("Table_name")); m_ctllist.addstring (StrfieldValue);} m_PRS-> MoveNext ();} m_prs-> close ();
Q Add #import "c: / program files / common files / system / ado / msado15.dll" no_namespace rename ("EOF", "EOF", "EOF", always compiled, said there is EditModeenum, RecordStatusenum, ParameterDirectionNum, LockTyPeenum, DatatyPeenum, FieldattributeEnum is defined! A changed to #pragma Warning (Disable: 4146) #import "c: / program files / common files / system / ado / msado15.dll" named_guids rename ("Eof", "AdoEOf"), rename ("Bof", " AdoBof ") # Pragma Warning (Default: 4146) Using namespace adoDB; after the error is not
Q How to get a table of data segment information (data type, length, name, etc.) a # include
#DEFINE PAUSE? Printf ("/ npress any key to exit"); getch ();
#define _win32_dcom
#pragma Warning (Push)
#pragma Warning (Disable: 4146)
#import "E: / Program Files / Common Files / System / ADO / MSADO15.DLL" No_Namespace Rename ("EOF", "ENDOFFILE")
#pragma Warning (POP)
Int main (int Argc, char * argv [])
{
_CONNECTIONPTR M_PCONN;
_RecordSetPtr M_PRS;
Coinitializeex (NULL, COINIT_MULTITHREADED);
_BSTR_T BSTRCONNSTR = "provider = microsoft.jet.Oledb.4.0;"
"Data Source = f: //lylong//db1.mdb; Persist security info = false";
Try {
m_pconn.createInstance (__UUIDOF (Connection));
M_PRS.CREATEINSTANCE (__UUIDOF (Recordset));
M_PCONN-> Open (BSTRCONNSTR, "," "", adConnectunSpecified;
M_PRS-> Open ("Table1",
m_pconn.getInterfacePtr (), AdopenForwardonly, AdlockOptimistic, Adcmdtable;
Long lcolumn = m_prs-> fields-> count; printf ("% - 12S% -10s% -10s / n", "field name", "length", "type"); for (long i = 0; i { Printf ("% - 12S% -10D% -10d / n", (char *) m_PRS-> fields-> item [i] -> name, m_prs-> fields-> item [i] -> definedsize, m_PRS- > Fields-> item [i] -> type);} m_prs-> close (); m_pconn-> close ();} catch (_COM_ERROR E) {printf ("/ n% s error:% ld / r / n ""% S / R / N ""% S / R / N ", (char *) e.Source (), E.Error (), (char *) E.DESCRIPTION (), (char *) e. ErrorMessage (); m_pcrs-> close (); m_pconn-> close ();} couuse; returnitialize (); pause; return 0;} Also See articles; ///dev.9cbs.net/Article/255578.shtm
Q How to read and write SQL ADO DateTimea write time value COLEDATETIME OLEDATE = COLEDATETIME :: getCurrentTime (); _ variant_t vtfld; vtfld.vt = vt_date; vtfld.date = oleDate; PRCORDSET4-> PUTCOLLECT ("Date", vtfld); Read time _BSTR_T thevalue = m_pset-> fields-> GetItem ("Birthday") -> Value; Temp = (Char *) Thevalue; Colevariant VTIME (TEMP); vTIME.CHANGETYPE (VT_DATE); COLEDATETIME TIME4 = VTIME ; // Read it is COLEDATETIME
How to determine whether there is a table Q ASTDMETHODIMP CADOTier :: get_IsExistTable (BSTR bsTable, long lType, VARIANT_BOOL * pVal) {ADODB access database :: _ RecordsetPtr pRstSchema = NULL; pRstSchema = m_connection-> OpenSchema (ADODB :: adSchemaTables); _bstr_t bsTableName (bsTable); _bstr_t table_name ( ""); _bstr_t table_type ( ""); char * pTemp1 = NULL, * pTemp2 = NULL; pTemp1 = _com_util :: ConvertBSTRToString (bsTableName); pTemp1 = strlwr (pTemp1); VARIANT_BOOL b = FALSE; while {table_name = pRstSchema-> Fields-> GetItem ( "tABLE_NAME") -> Value ((pRstSchema-> adoEOF)!); pTemp2 = _com_util :: ConvertBSTRToString (table_name); pTemp2 = strlwr (pTemp2); table_type = PRSTSCHEMA-> Fields-> GetItem ("Table_Type") -> Value; if (LTYPE == 1) // View Type {if (Table_TYPE ==_BSTR_T ("View")) {IF (Strcmp1, Ptemp2) = = 0) B = true;}}}} (LTYPE == 0) // Table Type {if (Table_TYPE == _BSTR_T ("Table")) {IF (strcmp1, ptemp2) == 0) B = true; }} PRSTSCH EMA-> MoveNext ();} // clean Up Objects Before exit. if (prStschema) IF (PRSTSCHEMA) IF (prStschema-> State == AdoDB :: AdStateOpen) prStschema-> Close (); * pval = b; returnif;}
Q Use code to automatically register an ODBC data source for the Access database under an engineering directory ACString spath; getModuleFileName (null, spath.getbuffersetlength; //); // Get the program path spath.ReleaseBuffer (); int NPOS ; npos = spath.reverseFind ('//'); spath = spath.left (npos = spath.reversefind ('//'); spath = spath.left (npos); cstract lpszfile = spath "//////// Lhwy.mdb "; // Get the full path of the database under the program directory char * szdesc; int mlen; szdesc = new char [256]; sprintf (szdesc," DSN =% s? description = TOC Support Source? DBQ =% s? FIL = Microsoft Access? defaultdir =% s ?? "," lhwy ", lpszfile, spath); // forms a SQLConfigDataSource function parameter string structure mlen = strlen (SZDESC); for (int i = 0; i {
IF (szdesc [i] == '?')
Szdesc [i] = '/ 0'; // Replace the upper string? Yes / 0, form a complete string
}
IF (false == sqlconfigDataSource (null, odbc_add_dsn, "Microsoft Access Driver (* .mdb) / 0", (LPCSTR) SZDESC) // Register Database
AfxMessageBox ("SqlconfigDataSource Failed");
Q SQL Server Implementation Fuzzy Query ASTRSQL.FORMAT ("SELECT * FROM Name WHERE Column LIKE '%%% S %%'", keyword);