数据库:DAO和ADO,Access和MSSQL等

Q access数据库SQL问题
T 有两个access的MDB文件(f1.mdb f2.mdb),每个文件里都有一个表为ta,ta有两个字段为"名称","数量",现在要合并这两个MDB文件的数据到第三个文件(f3.mdb该文件已经有一个空的表ta),第三个文件数据结构和这两个MDB文件一致。合并时如果名称相同则数量相加,我不想一条记录一条记录的处理。我在网上看到在access不同数据库中的表进行链接(in)介绍,我想用链接(in)类似下面代码解决问题
insert into ta(名称,数量) select * from 文件f1的ta,in 文件f2的ta group by  名称
请问这个SQL怎么写?
A select [name],sum([count]) as sumofcount
from query1
group by name
Q 想用access做个学生成绩统计的数据库,请问如何实现自动生成名次?
T 谢了
A 用一个查询就可以
比如按成绩顺序的话,你统计一下成绩比当前成绩多的学生数目就可以了
一点都不难

select rank=count(*), a1.studentname, a1.score
   from student a1, student a2
   where a1.score >= a2.score
   group by a1.studentname, a1.score
   order by a1.score


SELECT a1.studentid, a1.studentname, a1.score, Sum(a2.studentid) AS rank
FROM student AS a1, student AS a2
WHERE (((a1.score)>=[a2].[score]))
GROUP BY a1.studentid, a1.studentname, a1.score
ORDER BY a1.studentname, a1.score;
Q 高手请指教!!
T
以下是我有DAO技术访问ACCESS中的二进制信息:
 m_pRecordset->Move(81304);
 COleVariant BinaryValue;
 m_pRecordset->GetFieldValue("Index",BinaryValue);//"Index"是OLE型的
 UINT MyInt1[10];
 memcpy(MyInt1,BinaryValue.puintVal,40);
/
为什么取不出二进制信息呢?
A value的类型应该是VT_ARRAY吧……不能当int*使用的……

Visual C++ Concepts: Adding Functionality  
DAO Record Field Exchange (DFX)
DFX_BinarySee Also
MFC Macros and Globals | DFX_Text | DFX_Bool | DFX_Currency | DFX_Long | DFX_Short | DFX_Single | DFX_Double | DFX_DateTime | DFX_Byte | DFX_LongBinary | CDaoFieldExchange::SetFieldType
Transfers arrays of bytes between the field data members of a CDaoRecordset object and the columns of a record on the data source.

void AFXAPI DFX_Binary(
   CDaoFieldExchange* pFX,
   LPCTSTR szName,
   CByteArray& value,
   int nPreAllocSize = AFX_DAO_BINARY_DEFAULT_SIZE,
   DWORD dwBindOptions = 0
);
Q 请问:WIN98下怎样注册MSADO15.DLL这个组件? 用regsvr32.exe msado15.dll它说loadlibrary fail 
T MSADO15.DLL是从WIN XP HOME版拷过来的。我的程序在XP下运行正常,能使用access数据库。

把程序拷到WIN 98下,运行时非法操作,指向ADO的执行语句。在WIN98的系统目录下想注册MSADO15.DLL。命令行如下:
c:/pwin98/system/regsvr32.exe msado15.dll
报错:LoadLibrary("msado15.dll") fail!

我应该怎样注册这个ADO COM组件?? 谢谢!
A MSDN

MDAC SDK Technical Articles  
Redistributing Microsoft Data Access Components

ADO 2.7 Programmer's Guide 
Installing and Redistributing ADO

MDAC components consist of a matched set of dynamic-link libraries (DLLs). It is not enough to simply install Msado15.dll, for example, for ADO to work correctly. You need the complete set of ADO DLLs, as well as an underlying OLE DB provider (which usually has one DLL plus a set of helper DLLs) and ODBC.

You can download the latest version of MDAC_TYP.exe from the following Microsoft Web site:

http://www.microsoft.com/data/download.htm

The MDAC_TYP.exe setup includes only the binaries necessary to redistribute the components; it doesn't include documentation.

Note that in addition to MDAC_TYP.exe, you may need to distribute DCOM95 for your Windows 95 clients. DCOM must be installed prior to the installation of MDAC. Note that Windows 2000, Windows NT 4.0, and Windows 98 have DCOM built in. You can download the latest version of DCOM95 from the following Microsoft Web site:

http://www.microsoft.com/com
Note that DCOM must be installed separately and before MDAC_TYP.exe and your Setup program. DCOM cannot be installed from within your Setup program.
Q 吐血!如何从数据库中得到1970年以前的时间? 
T 用CRecordset类得到数据库中的时间的时候,发现对于1970年以前的时间,无论如何返回的都是1970-1-1,查MSDN才知道CRecordset交换时间用的是RFX_DATE,而这个返回的时间类型是CTime类型的,CTime类型的时间又限制在1970-2038,当时就快吐血了,各位老兄帮忙,分不够可以再加,只要解决这个问题啊。
A void AFXAPI DFX_DateTime(
   CDaoFieldExchange* pFX,
   LPCTSTR szName,
   COleDateTime& value,
   DWORD dwBindOptions = AFX_DAO_ENABLE_FIELD_CACHE
);
Q 如何创建ACCESS2000数据库.mdb文件
T 用ADO能否实现?
A 可以。也可以用SQLConfigDataSource创建。

Use of SQLConfigDataSource ODBC installer DLL API function:

BOOL fCreated;
fCreated = SQLConfigDataSource(NULL,
                        ODBC_ADD_DSN,
                       "Microsoft Access Driver (*.mdb)",
                       "CREATE_DB=.//ATest.mdb General/0" );
This will create ATest.mdb in the application's working directory using general sorting.

   BOOL SQLConfigDataSource(hwndParent, fRequest, lpszDriver,
                            lpszAttributes)
Where:
hwndParent is either NULL if no dialogs are to be displayed or a valid hwnd to act as parent to any driver generated dialogs.

fRequest is ODBC_ADD_DSN to specify creation of the .mdb file.

lpszDriver is Microsoft Access Driver (*.mdb).

lpszAttributes is "CREATE_DB=<path><filename>.mdb <sort order>/0" where the <path><filename> combination identifies where the file should be created and <sort order> is language sorting order (for example, General). <path> must be specified even if the .mdb is to be created in the current working directory. Use standard relative path syntax.
NOTE: Unlike most other ODBC API functions, SQLConfigDataSource returns a boolean value. This return value is TRUE if the .mdb was created, FALSE if creation failed.

Q 如何用ADO中的_RecordsetPtr对象做参数(变量)查询?
T 比如说:
_RecordsetPtr m_pRecordset;
m_pRecordset->("select * from 表名 where 字段名=一个变量",...)这句话改如何写?谢谢
A
#import "C:/Program Files/Common Files/System/ado/msado15.dll" /
           rename( "EOF", "adoEOF" )
   ...
   _variant_t  vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR);
   _variant_t  vtEmpty2(DISP_E_PARAMNOTFOUND, VT_ERROR);
   ...
   ADODB::_ConnectionPtr  Conn1;
   ADODB::_CommandPtr     Cmd1;
   ADODB::_ParameterPtr   Param1;
   ADODB::_RecordsetPtr   Rs1;

   // Trap any error/exception.
   try
   {
       // Create and Open Connection Object.
       Conn1.CreateInstance( __uuidof( ADODB::Connection ) );
       Conn1->ConnectionString =
                           _bstr_t(L"DSN=Biblio;UID=adimin;PWD=;");
       Conn1->Open( _bstr_t(L""), _bstr_t(L""), _bstr_t(L""), -1 );

       // Create Command Object.
       Cmd1.CreateInstance( __uuidof( ADODB::Command ) );
       Cmd1->ActiveConnection = Conn1;
       Cmd1->CommandText = _bstr_t(L"SELECT * FROM Authors "
                                   L"WHERE Au_ID < ?");

       // Create Parameter Object.
       Param1 = Cmd1->CreateParameter( _bstr_t(L""),
                                       ADODB::adInteger,
                                       ADODB::adParamInput,
     
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VC DAO 操作Access的测试例子,本演示是VC 使用DAO连接Access数据库的一个测试程序,学习如何使用DAO操作Access,通过添加一个数据库记录来演示添加、删除、插入数据的例子,比较简单,面向VC 初学者的一个例子。部分代码分享如下:   // 取得被选择记录的索引   nIndexInFieldList = m_listctrlInfo.GetNextSelectedItem(pos);   // 高亮被的选择记录   m_listctrlInfo.SetFocus();   // 从文件中把当前行记录删除   // 获取数据库文件   m_csDatebaseFile = GetDatabaseFile();   // 判断数据库是否已经打开   if (!m_bIsOpenDB)   {    db.Open(m_csDatebaseFile);    // 判断数据集是否已经打开    if (!m_bIsOpenDSN)    {    RecSet.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM PositionTable",NULL);    }   }   m_nTotal = m_listctrlInfo.GetItemCount();   m_nCurrentIndex = ConvertIndex(nIndexInFieldList,m_nTotal - 1);   RecSet.MoveFirst();   RecSet.Move(long(m_nCurrentIndex));   RecSet.Delete();   ClearContent();   // 删除被的选择记录   m_listctrlInfo.DeleteItem( nIndexInFieldList );   // 显示删除数据成功的信息   GetDlgItem(IDC_STATIC_INFO)->SetWindowText(_T("删除数据成功!"));   // 再次取得第一条记录的位置   POSITION pos = m_listctrlInfo.GetFirstSelectedItemPosition();   UINT flag = LVIS_SELECTED|LVIS_FOCUSED;   m_listctrlInfo.SetItemState( nIndexInFieldList, flag, flag );

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值