19317.html

来自「VB技巧问答10000例 VB技巧问答10000例」· HTML 代码 · 共 23 行

HTML
23
字号
<html>  <head>    <title>Re: Add datasource in ODBC by VB code??</title>  </head>  <body bgcolor="#FFFFFF" vlink="#808080">    <center>      <h1>Re: Add datasource in ODBC by VB code??</h1>    </center><hr size=7 width=75%><hr size=7 width=75%><p>Posted by <a href="mailto:dumbjames@hotmail.com">dumbjames</a> on September 26, 1999 at 04:31:08:<p>In Reply to: <a href="19289.html">Add datasource in ODBC by VB code??</a> posted by Joewall88 on September 24, 1999 at 12:01:29:<p>:Can i use vb code to create a new datasource in ODBC in run time rather than just manually establish the datasource in control panal of windows? Can any experts help me?<p>Good question you've asked. I have been wondering this too.<br>Sure you can. Just add this code to your module and call it as you would any function(please customize the code): (the orginal code is from VBPJ,VBTIPS 101)<p>' Declaration<br>Declare Function SQLConfigDataSource lib "OBDCCP32.DLL" (byval hwndParent as long, byval fRequest as long, byval lpszDriver as string, byval lpszAttributes as string) as long<p>' Function<br>public sub MakeODBCDataSource()<br>' Indent!!!<br>Const ODBC_ADD_DSN=1<br>Const ODBC_CONFIG_DSN=2<br>Const ODBC_REMOVE_DSN=3<br>Const vbAPINull as long = 0&<br>dim lngRet<br>' you got to check is there is already one dsn you set up<br>if getsetting(app.exename,"options","ODBCSetup","no")="no" then<br> dim sDeiver as string<br> dim sAttributes as string<br> sDriver="Microsoft Access Driver (*.mdb)"<br> sAttributes=sattributes & "DSN=MyDSN" & chr(0)<br> sAttributes=sattributes & "DBQ=C:\Temp\Myfile.mdb" & chr(0)<br>lngRet=SQLCONFIGDATASOURCE(VBAPINULL,ODBC_ADD_DSN,Sdriver,sattributes)<br>savesetting app.exename,"options","odbcsetup","yes"<br>endif<br>end sub<br><br><hr size=7 width=75%><p><a name="followups">Follow Ups:</a><br><ul><!--insert: 19317--></ul><!--end: 19317--><br><hr size=7 width=75%><p></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?