ODBC(http://www.csdn.net/expert/topic/911/911449.xml?temp=.100033)

ap97091 2002-07-31 11:25:34
http://www.csdn.net/expert/topic/911/911449.xml?temp=.100033
...全文
160 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ap97091 2002-08-01
  • 打赏
  • 举报
回复
我要VC的
那些英文很简单嘛,如果是别的人的贴子,我就把它翻译过来,这样就有分收了。
自己不能给自己加分,不翻译。
_Shakespeare 2002-07-31
  • 打赏
  • 举报
回复
VB实现的
SQLConfigDataSource Example
The following example uses the ::SQLConfigDataSource ODBC API function
to create a new Excel data source called “New Excel Data Source”:

SQLConfigDataSource(NULL,ODBC_ADD_DSN, "Excel Files (*.xls)",
"DSN=New Excel Data Source\0"
"Description=New Excel Data Source\0"
"FileType=Excel\0"
"DataDirectory=C:\\EXCELDIR\0"
"MaxScanRows=20\0");

Note that the data source is actually a directory (C:\EXCELDIR); this
directory must exist. The Excel driver uses directories as its data
sources, and files as the individual tables (one table per .XLS file).

For additional information on creating tables, see the article Data
Source: Programmatically Creating a Table in an ODBC Data Source.

The information below discusses the parameters that need to be passed to the ::SQLConfigDataSource ODBC API function. To use ::
SQLConfigDataSource, you must include the ODBCINST.H header file and use
the ODBCINST.LIB import library. Also, ODBCCP32.DLL must be in the path
at run time (or ODBCINST.DLL for 16 bit).

You can create an ODBC data source name using the ODBC Administrator
program or a similar utility. However, sometimes it is desirable to
create a data source name directly from your application to obtain
access without requiring the user to run a separate utility.

The ODBC Administrator (typically installed in the Windows Control
Panel) creates a new data source by putting entries in the Windows
registry (or, for 16 bit, in the ODBC.INI file). The ODBC Driver Manager
queries this file to obtain the required information about the data
source. It’s important to know what information needs to be placed in
the registry because you'll need to supply it with the call to ::
SQLConfigDataSource.

Although this information could be written directly to the registry
without using ::SQLConfigDataSource, any application that does so is
relying on the current technique that the Driver Manager uses to
maintain its data. If a later revision to the ODBC Driver Manager implements record keeping about data sources in a different way, then
any application that uses this technique would be broken. It is
generally advisable to use an API function when one is provided. For
example, your code is portable from 16 bit to 32 bit if you use the ::
SQLConfigDataSource function, as the function will correctly write to
the ODBC.INI file or to the registry.

SQLConfigDataSource Parameters
The following explains the parameters of the ::SQLConfigDataSource
function. Much of the information is taken from the ODBC API
Programmer's Reference supplied with Visual C++ version 1.5 and later.

Function Prototype
BOOL SQLConfigDataSource(HWND hwndParent,UINT fRequest, LPCSTR
lpszDriver, LPCSTR lpszAttributes);

Parameters and Usage
hwndParent The window specified as the owner of any dialog boxes
that either the ODBC Driver Manager or the specific ODBC driver
creates to obtain additional information from the user about the new
data source. If the lpszAttributes parameter doesn’t supply enough
information, a dialog box appears. The hwndParent parameter may be NULL; see the ODBC Programmer’s Reference for details.

lpszDriver The driver description. This is the name presented to users
rather than the physical driver name (the DLL).

lpszAttributes List of attributes in the form “keyname=value”. These
strings are separated by null terminators with two consecutive null
terminators at the end of the list. These attributes are primarily
default driver-specific entries, which go into the registry for the
new data source. One important key that is not mentioned in the ODBC API
reference for this function is “DSN” (“data source name”), which
specifies the name of the new data source. The rest of the entries are
specific to the driver for the new data source. Often it is not
necessary to supply all of the entries because the driver can prompt the
user with dialog boxes for the new values. (Set hwndParent to NULL to
cause this.) You might want to explicitly supply default values so
that the user is not prompted.
cywater2000 2002-07-31
  • 打赏
  • 举报
回复
UP
ap97091 2002-07-31
  • 打赏
  • 举报
回复
两个贴子问的是同一个问题,但分有两倍。
petkoala 2002-07-31
  • 打赏
  • 举报
回复
老大!你有什么意思啊~~~~~~

34,872

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧