Thread View: cn.bbs.comp.program
1 messages
1 total messages
Started by ���ܵ�Сʨ
Sat, 18 Apr 1998 00:00
VC4.0��ODBC���� ��¼���붯̬������ʵ�ֱ�̼
Author: ���ܵ�Сʨ
Date: Sat, 18 Apr 1998 00:00
Date: Sat, 18 Apr 1998 00:00
199 lines
10796 bytes
10796 bytes
���ò����¼���붯̬������ODBCӦ�ó�������߳�������
Ч�ʵij��÷���������C����ֱ�ӵ���ODBC������������,VC4.0��
������MFC������ṩ�˷����ʵ�������������ֶΡ����潫
�������VC4.0�в����¼���붯̬������ʵ�֡�
�����¼���붯̬��
������ODBC����Client/ServerӦ�ó���Ĺ����,����Ա��Ȼ��
�������������:��ο��ٸ�Чִ�в�ѯ����,��Ҫ�������Client/S
erver�ṹ���ŵ�,��Ҫ������ռ����ݿ����������Դ����VC4.0��
���õķ������ȸ�ݱ�Ľṹ����Class Wizard���һ����Ӧ���CR
ecordSet��������,Ȼ���ݲ�ͬ�IJ�ѯ������ɸѡ�ַ������
�ݳ�Աm_strField��ֵ,������Requery()��Ա�����Եõ�����ָ����
���ļ�¼��������,ͨ����������ִ�й�̼�MFC��Դ�����֪:��
ÿ�ν���һ���µ�ɸѡ�ַ��,CRecordSet�������Ӧ�ı�Ľ�
�����һ��SQL���,����ODBC������ύ�������ִ�С���������
�ӵ������Ժ�����Ҫ�Դ�SQL������������Լ��Ż�,��SQL���
����IJ����ֽ�,Ȼ���ύ���������ݿ�����ִ��,�������ս��
���ظ�ͻ�������ɸѡ�ַ������ͬ����ʽ�����ֻ��ɸѡ����
ȡֵ��ͬʱ,ÿ�ν���������ͬ�IJ����������˷ѷ���������Դ��
����������ODBC�ӿ��ṩ�˲����¼���Ĺ���,���������
һ������ͨ��һЩ������ѯ�����ļ�¼��,ֱ������Щ�����
���Եõ����㲻ͬ�����ļ�¼�����������ڲ����¼���в���ֱ��
���ݸ���ݿ�����,������ÿ�ζ���ͬ��SQL��������������,���
��������SQL����ִ��Ч��,�ر�������ظ��ġ��ṹ���ƵIJ�ѯ
,������߸������̬����������Ӧ�ó����ݲ�ͬ������
��ͬ�������,��������ڳ���������һ��CRecordSet��ʵ���
��洢������е���ݻ��߲����û��ڳ�����������ɵ��±�(��Ϊ
����Class Wizard���CRecordSet��������ʱ,��������ȷ���ı��
�ṹ)������ڼ��ٳ���ռ�û�����Դ�Լ���߳��������Ծ�����
Ҫ���塣
�����¼����ʵ��
������һ��ѧ��ѧ����Ϊ��,ͨ�����һ����ѧ��ѧ����Ϊ����
�ļ�¼����˵��VC4.0�в����¼����ʵ�֡��ñ�Ľṹ����:
��1
������������:
1.����VC4.0�е�Class Wizard���ߴ�����Ӧ��Student Table��
CRecordSet���������CStudentSet��
2.��CStudentSet��ͷ�ļ���Ϊ�������һ�����е�CString���
��ݳ�Աm_strStuden t_Param,ע�����ݳ�Ա�������һ��AFX_FI
ELDע��֮�⡣
//��һ��AFX_FIELDע��֮�ж���ı����������ж�Ӧ�ı���
��
//{{AFX-FIELD(CStudentSet,CRecordSet)
CString m_Student_Name;
CString m_Student_NO;
CString m_Home_Address;
CString m_Telephone_NO;
CString m_Home_Zip;
//}}AFX_FIELD
//�������ж�Ӧ�ı���
CString m_strStudent_Param;
3.���µij�Ա�����ӵ�DoField Exchange������,��������ͨ��
�÷������ݵ��������ȥ�ġ��ڰѲ������ӵ�DoFieldExchange��
��֮ǰ,�����ȵ���SetFieldType�������������ֶ��Dz���ֵ��
void CStudentSet::DoFieldExchange(CFieldExchange * pFX)
{
//{{AFX_FIELD_MAP(CStudentSet)
pFX->SetFieldType(CFieldExchange::outputColumn);
//˵������
RFX->Text(pFX,_T("[Student_Name]"),m_Student_Name);
RFX->Text(pFX,_T("Student_NO"),m_Student_NO);
RFX->Text(pFX,_T("[Home_Address��"),m_Home_Address);
RFX->Text(pFX,_T("[Telephone_NO��"),m_Telephone_NO);
RFX->Text(pFX,_T("[Home_Zip��"),m_Home_Zip);
//}}AFX_FIELD_MAP
pFX->SetFieldType(CFieldExchange::param);
//˵������
RFX->Text(pFX,_T("Studnet-NO"),m_strStudent_Param);
}
4.��������ɸѡ�ַ�,�ڹ��캯���н�CStudentSet�д�CRec
ordSet�̳е���ݳ�Աm_strField��ʼ���ɰ�δ֪�������ʽ;ͬ
ʱ��ʼ�������m_nParam��
CStudentSet::CStudentSet(CDatabase * pDb):CRecordSet(m_p
Db)
{
//�����ʼ��
//{{AFX_FIELD_INIT(CWhiteboardSet)
m_Student_Name=_T("");
m_Student_NO=_T("");
m_Home_Address=_T("");
m_Telephone_NO=_T("");
m_Home_Zip=_T("");
m_nFields=5;//������Ŀ
//}}AFX_FIELD_INIT
m_strStudent_Param=_T("");
m_nParams=1;//������Ŀ
m_strFilter="Student-NO=?";
}
����"?"�����������ڵ�λ��,�ڰ�������������,ODBC
���潫��DoFieldExcha nge�����в�����ֵ�˳���滻m_strField��
���ʺš�m_nParam��ֵ����������ʵ�ʸ������,��������һЩ
���Ծ���Ĵ���
����,ÿ�θ��ѧ��ѧ��������ѧ����Ϣʱ,ֻ���Ϊm_strS
tudent_Param��ֵ,������Requery()��ɵõ���ѧ�ŵ�ѧ����Ϣ��
��̬��ʵ��
��������Student TableΪ��,�����������ڸ���û���ѡ��ֻ��
Ҫ��Student_NO�к����������е�ijһ�л�ij���С�
����,������CStudentSet�м���һ��CStringList��Ա������һ
��CObList��Ա����,����CStringList���ڴ���ֶ���,CObList����
�����CStringList�ֶ����Ӧ�ı�����ָ�롣
���,��DoFieldExchange������
ע���ڵ���Requery()��ǰ������m_nField��ֵ:
m_nField=m_Column_List.GetCount();
����,ͨ����m_Column_List��m_Storage_List�гɶԵ������ֶ�
��Ͷ�Ӧ�ı�����,����ʵ�ֶ�̬��
���ж�̬�����Ե�CStudentSet�����ϸ�ṹ��ʵ������:
// studentSet.h CStudentSet��ͷ�ļ�
class CStudentSet:public CRecordset
{
public:
CStudentSet(CDatabase* pDatabase=NULL);
DECLARE_DYNAMIC(CStudentSet)
//����
//{{AFX_FIELD(CStudentSet,CRecordset)
CString m_Student_Name;
CString m_Student_NO;
CString m_Home_Address;
CString m_Telephone_NO;
CString m_Home_Zip;
//}}AFX_FIELD
//��Ӵ洢��̬���������
public:
CStringList m_Column_List;
CObList m_Storage_List;
//{{AFX_VIRTUAL(CStudentSet)
public:
virtual CString GetDefultConnect();
// Default connection string
virtual CString GetDefaultSQL();
//default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX);
//RFX support
//}}AFX_VIRTUAL
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext & dc) const;
#endif
};
// studentSet.cpp CStudentSet ��CPP�ļ�
#include "stdafx.h"
#include "student.h"
#include "studentSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE����=--FILE--_;
#endif
IMPLEMENT_DYNAMIC(CStudentSet,CRecordset)
CStudentSet::CStudentSet(CDatabase* pdb): CRecordset(pdb
)
{ //�����ʼ��
//{{AFX_FIELD_INIT(CStudentSet)
m_Student_Name=_T("");
m_Student_NO=_T("");
m_Home_Address=_T("");
m_Telephone_NO=_T("");
m_Home_Zip=_T("");
m_nFields=5;
//}}AFX_FIELD_INIT
m_nDefaultType=snapshot;
}
CString CStudentSet::GetDefaultConnect()
{
return _T("ODBC;DSN=Student");
}
CString CStudentSet::GetDefaultSQL()
{
return _T("Student");
}
//��DoFieldExchange��������
void CStudentSet::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CStudentSet)
pFX->SetFieldType(CFieldExchange::outputColumn);
POSITION pos=m_Column_List.GetHeadPosition();
while(pos!=NULL)
RFX_Text(pFx,m_Column_List.GetNext(pos),
*m_Storage_List.GetNext(pos));
//}}AFX_FIELD_MAP
}
//CStudentSet diagnostics
#ifdef _DEBUG
void CStudentSet::AssertValid() const
{
CRecordset::AssertValid();
}
void CStudentSet::Dump(CDumpContext& dc) const
{
CRecordset::Dump(dc);
}
#endif //_DEBUG
--
[m[1;32m�� ��Դ:���ϴ�С�ٺ���Ϣ����վ bbs.nju.edu.cn��[FROM: hsia.nju.edu.cn][m
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads