[access数据库实习心得]Microsoft Access在很多地方得到广泛使用,例如小型企业,大公司的部门,和喜爱编程的开发人员专门利用它来制作处理数据的桌面系统。它也常被用来开发简单的WEB应用程序.这些应用...+阅读
#import "C:\program files\common files\system\ado\msado15.dll " no_namespace rename( "EOF ", "adoEOF ") //#import "c:\program files\common files\system\ado\msado15.dll " rename ( "EOF ", "adoEOF ") no_namespace #define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \ if (FAILED(_hr)) _com_issue_error(_hr); } #define RsITEM(rs,x) ((rs->Fields->Item[_variant_t(x)]->Value)) class CHmbAdoDB { public: BOOL m_bOpen; _ConnectionPtr m_DbConn; CString m_ErrMsg; CString m_SQLState; long mSqlCode; public: void Cancel(); BOOL IsOpen(); void RollbackTrans(); void CommitTrans(); long BeginTrans(); void Close(); BOOL Open(LPCSTR lpszConnect); BOOL Execute(LPCTSTR lpSQL); void ProviderError(); CHmbAdoDB() { } virtual ~CHmbAdoDB() { } }; class CHmbAdoDBRs : public CObject { public: _RecordsetPtr m_Rs; public: CHmbAdoDBRs(); virtual ~CHmbAdoDBRs(); BOOL Open( CHmbAdoDB *pDB, LPCSTR szSource,long option=-1); void Close(); void GetRs(_variant_t x,_bstr_t &ret); void GetRs(_variant_t x,CString &ret); BOOL IsEOF(); BOOL IsOpen(); BOOL MoveNext(); BOOL MovePrev(); BOOL MoveFirst(); BOOL MoveLast(); }; #endif // !defined(AFX_RfidAdoDB_H__7C539954_1C62_47B6_AB6E_1A5BB73A67E5__INCLUDED_) truct InitOle { InitOle() { ::CoInitialize(NULL); } ~InitOle() { ::CoUninitialize(); } } _init_InitOle_; long mSqlCode; BOOL CHmbAdoDB::Open(LPCSTR lpszConnect) { try { CREATEiNSTANCE(m_DbConn,Connection); m_DbConn->Open(lpszConnect, " ", " ", adModeUnknown ); } catch( _com_error &e) { return FALSE; } catch(...) { return FALSE; } return TRUE; } void CHmbAdoDB::Close() { if( IsOpen() ) { m_DbConn->Close(); } } long CHmbAdoDB::BeginTrans() { return m_DbConn->BeginTrans(); } void CHmbAdoDB::CommitTrans() { m_DbConn->CommitTrans(); } void CHmbAdoDB::RollbackTrans() { m_DbConn->RollbackTrans(); } void CHmbAdoDB::Cancel() { m_DbConn->Cancel(); } BOOL CHmbAdoDB::IsOpen() { return ( (m_DbConn->GetState() != 0) ? TRUE : FALSE ); } BOOL CHmbAdoDB::Execute(LPCTSTR lpSQL) { if (!IsOpen()) { AfxMessageBox( "Network error, Database do not open. "); return FALSE; } CString strSQL(lpSQL); strSQL.TrimLeft(); strSQL.TrimRight(); try { m_DbConn->Execute(_bstr_t(strSQL), NULL, adExecuteNoRecords); } catch( _com_error &e) { return FALSE; } catch(...) { return FALSE; } return TRUE; } void CHmbAdoDB::ProviderError() { // Print Provider Errors from Connection object. // pErr is a record object in the Connection 's Error collection. ErrorPtr pErr = NULL; if( (m_DbConn->Errors->Count) >0) { long nCount = m_DbConn->Errors->Count; // Collection ranges from 0 to nCount -1. for(long i = 0; iErrors->GetItem(i); mSqlCode = pErr->NativeError; m_ErrMsg.Format( "SQLCODE : %ld\t%s ",mSqlCode, LPCTSTR(pErr->Description)); m_SQLState.Format( "%s ",(char*)pErr->SQLState); printf( "%s // %s\n ",m_SQLState,m_ErrMsg); } } m_DbConn->Errors->Clear(); } CHmbAdoDBRs::CHmbAdoDBRs( ) { } CHmbAdoDBRs::~CHmbAdoDBRs() { } BOOL CHmbAdoDBRs::Open( CHmbAdoDB *pDB, LPCSTR szSource,long option ) { CString strSQL; strSQL = CString(szSource); strSQL.TrimLeft(); strSQL.TrimRight(); _variant_t vRecsAffected(0L); // CREATEiNSTANCE( m_Rs,Recordset) ; // m_Rs->PutRefActiveConnection( pDB->m_DbConn ); try { m_Rs = pDB->m_DbConn->Execute(_bstr_t(strSQL), &vRecsAffected, adOptionUnspecified); m_Rs->AddRef(); // m_Rs->Open(szSource, vtMissing, adOpenKeyset, adLockBatchOptimistic, adOptionUnspecified); // m_Rs->Open(szSource, vtMissing, adOpenKeyset, adLockReadOnly, option); // m_Rs->Open(szSource,pDB->m_DbConn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic, adCmdText); } catch( _com_error &e) { //ErrorMessage(); m_Rs->Close(); m_Rs->Release(); return FALSE; } catch(...) { m_Rs->Close(); m_Rs->Release(); return FALSE; } return TRUE; } void CHmbAdoDBRs::Close() { m_Rs->Close(); m_Rs->Release(); } void CHmbAdoDBRs::GetRs(_variant_t x,_bstr_t &ret) { ret = (m_Rs->Fields->Item[x]->Value); } void CHmbAdoDBRs::GetRs(_variant_t x,CString &ret) { _bstr_t retVal; try{ retVal = (m_Rs->Fields->Item[x]->Value); } catch(...){ ret = " "; return; } ret = CString((char*) retVal); } BOOL CHmbAdoDBRs::IsEOF() { return m_Rs->adoEOF; } BOOL CHmbAdoDBRs::IsOpen() { return ( (m_Rs->GetState() != 0) ? TRUE : FALSE ); } BOOL ...
以下为关联文档:
C语言数据结构与算法分析C语言描述Position不是一个类型,起码C语言中,我写那么多年代码没见过这个类型 。你该把整段代码贴上来。我猜你看的那段代码是伪代码,Position是自定义类型。若Position是类名,那么Positi...
c语言连接字符串#include<stdio.h> void main() { char a[80],b[40]; int i=0,j=0; printf("input string1:"); scanf("%s",a); //输入字符串a printf("input string2:"); scanf("%s",b); //输入字符...
C语言编写字符串连接int i=0,j; char ch; char str1[100],str2[100]; printf("请输入2个字符串:\n"); scanf("%s %s",str1,str2); printf("合并前str1:%s,str2:%s\n",str1,str2); strcat(str1,str2); while...
C语言连接字符串问题正确答案: #include<stdio.h> main() { int i,j,k,l; char str1[10],str2[10],str3[20]; scanf("%s",str1); scanf("%s",str2); i=sizeof(str1); j=sizeof(str2); for(k=0;k<i;k+...
C语言字符串连接问题Please input str1:123 Please input str2:456 123456 Press any key to continue #include <stdio.h> char*mystrcat(char*str1,char*str2); void main() { char str1[50];...
易语言数据库连接和外部数据提供者两个组件有什么区别外部数据提供者用作为数据源提供对外部ODBC数据库的存取操作。它使用外部数据库作为数据的存储仓库,不支持备注和长字节集类型字段,不支持以下数据操作接口: 1、置行高; 2、置类...
VS2005中使用C语言连接SQL数据库然后实现插入数据的方法try { String commandText="select count(*) from users"; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=(local);Initial Catalog=class...
我使用asp的VB语言来连接access的数据库但是连接不上不知是哪<% txtname = request.form("txtname") txtpassword = request.form("txtpassword") txtmail = request.form("txtmail") dsnpath = server.MapPath("database/UserData.mdb") conns...
纯C语言怎样连接数据库你先配置数据库 然后举个例子,连接SQL 我连access的给你看一下 别忘了 mfc AfxOleInit(); 或者 win32 coInitial什么东东(初始化com的) // 打开数据库 strDBClass.Format(_T("Prov...