ADO accessing database access source code of the image type field

Source: Internet
Author: User

Ado header file code:

# If! Defined (afx_ado_ado_h00009f3bd0b450a877_4b35_9dce_e73e49efe0c500000000ded _)
# Define afx_ado_ado_h00009f3bd0b450a877_4b35_9dce_e73e49efe0c500000000ded _

# If _ msc_ver> 1000
# Pragma once
# Endif // _ msc_ver> 1000

Class ado_ado
{
Public:
_ Connectionptr m_pconnection; // connection object pointer
_ Recordsetptr m_precordset; // record set object pointer
Public:
Ado_ado ();
Virtual ~ Ado_ado ();
Void oninitadoconn (); // connect to the database
_ Recordsetptr & openrecordset (cstring SQL); // open the record set
Void closerecordset (); // close the record set
Void closeconn (); // closes the database connection
Uint getrecordcount (_ recordsetptr precordset); // obtain the number of records
};

# Endif

 

Code of the ADO function implementation file:

# Include "stdafx. H"
// # Include "ADO. H"
# Include "ado_ado.h"

# Ifdef _ debug
# UNDEF this_file
Static char this_file [] =__ file __;
# Define new debug_new
# Endif

//////////////////////////////////////// //////////////////////////////
// Construction/destruction
//////////////////////////////////////// //////////////////////////////

Ado_ado: ado_ado ()
{

}

Ado_ado ::~ Ado_ado ()
{

}
Void ado_ado: oninitadoconn ()
{
: Coinitialize (null); // afxoleinit (); initialize the com Library
/* // "Provider = sqloledb; persist Security info = false; uid = sa; Pwd =;
// Initial catalog = text; Data Source = Lenovo/simple ;"
----- ADO database connection string template for connecting to SQL Server ----------
[1] Authentication Mode: "SQL Server and Windows"
"Provider = sqloledb.1; persist Security info = true; user id = user name; Password = password;
Initial catalog = database name; Data Source = SQL server name"
[2] Authentication Mode: "Windows only"
"Provider = sqloledb.1; Integrated Security = sspi; persist Security info = false;
Initial catalog = database name; Data Source = SQL server name"
"DSN =; uid = sa; Pwd =; server = ntserver; provider = sqloledb; database = text "*/
Try
{
M_pconnection.createinstance ("ADODB. Connection"); // create a connection object instance
_ Bstr_t strconnect = "provider = sqloledb.1; persist Security info = true; user id = sa; Password =; initial catalog = dscdtsdb; Data Source = 192.168.0.125 ";
M_pconnection-> open (strconnect, "", "", admodeunknown); // open the database
}
Catch (_ com_error E)
{
Afxmessagebox (E. Description (); // an error occurs.
}
}
_ Recordsetptr & ado_ado: openrecordset (cstring SQL)
{
Assert (! SQL. isempty (); // The SQL statement cannot be empty.
Try
{
M_precordset.createinstance (_ uuidof (recordset); // create a record set object instance
M_precordset-> open (_ bstr_t (SQL), m_pconnection.getinterfaceptr (),
Adopendynamic, adlockoptimistic, adshorttext); // run the SQL statement to obtain the record set.
}
Catch (_ com_error E)
{
Afxmessagebox (E. Description ());
}
Return m_precordset; // returns the record set pointer.
}
Void ado_ado: closerecordset ()
{
If (m_precordset-> getstate () = adstateopen) // you can determine the status of the current record set.
M_precordset-> close (); // close the record set
}
Void ado_ado: closeconn ()
{
M_pconnection-> close (); // close the database connection
: Couninitialize (); // m_pconnection-> release (); //: couninitialize (); // release the com Environment
}
Uint ado_ado: getrecordcount (_ recordsetptr precordset)
{
Int ncount = 0; // declare the variable that saves the number of records
Try
{
Precordset-> movefirst (); // move the record set pointer to the first record
}
Catch (...) // catch possible errors
{
Return 0;
}
If (precordset-> adoeof)
Return 0;
While (! Precordset-> adoeof)
{
Precordset-> movenext ();
Ncount ++;
}
Precordset-> movefirst ();
Return ncount; // number of returned records
}

 

 

 

ADO object definition

Ado_ado m_ado_dd8tb;

 

Read database code:

M_ado_dcdtb.oninitadoconn ();
Ctime tnow = ctime: getcurrenttime ();
Cstring strcurrday = tnow. Format ("% Y-% m-% d ");
Cstring strsql;
Strsql. Format ("select * From dscdatatb where storage date = '% s' order by storage time", strcurrday );
M_ado_dcdtb.m_precordset = m_ado_dcdtb.openrecordset (strsql );
// Char wendushuju [1, 5120] = {0 };
Char * m_pbmpbuffer = NULL;
_ Variant_t pvlist;
Long ldatasize;
While (! M_ado_dcdtb.m_precordset-> adoeof)
{
Cstring guangxianno = (char *) (_ bstr_t) m_ado_ddxtb.m_precordset-> getcollect ("Storage Time ");
Ldatasize = m_ado_ddxtb.m_precordset-> getfields ()-> getitem (_ variant_t ("temperature data")-> actualsize;
If (ldatasize> 0)
{
_ Variant_t varblob;
Varblob = m_ado_dsp_tb.m_precordset-> getfields ()-> getitem (_ variant_t ("temperature data")-> getchunk (ldatasize );
If (varblob. Vt = (vt_array | vt_ui1 ))
{
M_pbmpbuffer = new char [ldatasize + 1];
Char * pbuf = NULL;
Safearrayaccessdata (varblob. parray, (void **) & pbuf );
Memcpy (m_pbmpbuffer, pbuf, ldatasize );
Safearrayunaccessdata (varblob. parray );
}
}
M_ado_dcdtb.m_precordset-> movenext ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.