When using C + + to access Oracle, ODBC is an option and the DSN needs to be configured when CDatabase is used for OpenEx. Here's how to configure DSN
- Open ODBC Data Source Manager (ORC1 I have configured, not before configuration)
Click "Add" and a dialog box appears:
Select Oracle in Oraclinetxxx, after the XXX representative version is different, may be different, click "Done"
The TNS Service Name is optional (my ORCL), select it, fill in the Data Source Name and User ID, and then click "Test Connection" to indicate success.
And then use it when programming.
CDatabase DB;
Db. OpenEx (_t ("DSN=ORC1; Uid=uid; Pwd=pwd "), Cdatabase::openreadonly | Cdatabase::noodbcdialog); DSN is the last name of the first picture, the UID is my id,pwd is my password
2 using Cdbimage to read a blob of a database
The variables defined in the DBIMAGES.H must be consistent with the name of the database table. If there is AAA in the table, then the definition is AAA. If the BLOB has a column name of BBB, the CLongBinary BBB is defined.
In the CPP file
CString Cdbimages::getdefaultsql ()
{
Return _t ("[TABLENAME]"); //In parentheses indicates that the name of the table to be queried
}
Others can be configured with reference to other tutorials.
If you read directly, you can use the
Cdbimages dbimages (&DB);
Dbimages.open ();
At this point, the BBB value for the first row of the table is obtained. If you need to get the value of BBB for AAA = ' AAA ', that is: select BBB from TABLENAME where aaa= ' aaa ' can:
CString Bbb_str;
CString aaa_str = L "AAA";
DbImages.m_strFilter.Format (L "aaa= '%s '", AAA_STR);
if (Dbimages.open (crecordset::snapshot,l "TABLENAME"));
{
What you get is the data you want.
}
3 CString saved to TXT document
In the case of Unicode, the result is a string of 16-bit binary data saved with Ofstream. This is because the address is saved, not the data itself. You can do this by:
CString str = "CSTRING_STR";
CStringA stra (str);
Std::ofstream outfile;
Outfile.open ("Save.txt", ios::out);
outfile<<stra;
Outfile.close ();
Data from Str can be saved.