CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

数据库配置文件。。。

楼主sutdy(好好学习,天天向上)2005-10-17 22:48:43 在 VB / 基础类 提问

用vb写了个数据库管理的例子,想写个配置文件配置数据库,到用户哪儿可以根据配置文件来修改数据库连接串。  
  数据库是:sql   server   2000怎么做? 问题点数:20、回复次数:4Top

1 楼faysky2(出来混,迟早是要还嘀)回复于 2005-10-18 00:40:40 得分 10

Option   Explicit  
   
  '读写INI的API函數  
  Public   Declare   Function   WritePrivateProfileString   Lib   "kernel32"   Alias   "WritePrivateProfileStringA"   (ByVal   lpApplicationName   As   String,   ByVal   lpKeyName   As   Any,   ByVal   lpString   As   Any,   ByVal   lpFileName   As   String)   As   Long  
  Public   Declare   Function   GetPrivateProfileString   Lib   "kernel32"   Alias   "GetPrivateProfileStringA"   (ByVal   lpApplicationName   As   String,   ByVal   lpKeyName   As   Any,    
  ByVal   lpDefault   As   String,   ByVal   lpReturnedString   As   String,   ByVal   nSize   As   Long,   ByVal   lpFileName   As   String)   As   Long  
   
  '自定义写入INI函數  
  Public   Function   WriteIni(ByVal   section   As   String,   ByVal   key   As   String,   ByVal   value   As   String)   As   Boolean  
  Dim   x   As   Long,   Buff   As   String   *   128,   I   As   Integer  
  Buff   =   value   +   Chr(0)  
  x   =   WritePrivateProfileString(section,   key,   Buff,   App.Path   +   "\MenuSetting.ini")  
  WriteIni   =   x  
  End   Function  
   
  '自定义读取INI函數  
  Public   Function   ReadIni(ByVal   section   As   String,   ByVal   key   As   String)   As   String  
  Dim   x   As   Long,   Buff   As   String   *   128,   I   As   Integer  
  x   =   GetPrivateProfileString(section,   key,   "",   Buff,   128,   App.Path   +   "\MenuSetting.ini")  
  I   =   InStr(Buff,   Chr(0))  
  ReadIni   =   Trim(Left(Buff,   I   -   1))  
  End   Function  
   
   
   
  '删除INI文件中指定的键  
  Public   Sub   DelKeyINI(ByVal   iniFileName   As   String,   ByVal   iniSection   As   String,   ByVal   iniKey   As   String)  
          WritePrivateProfileString   iniSection,   iniKey,   vbNullString,   iniFileName  
  End   SubTop

2 楼cuilei197979(风)回复于 2005-10-18 07:32:32 得分 10

在类模块中写代码  
  Declare   Function   GetPrivateProfileString   Lib   "kernel32"   Alias   "GetPrivateProfileStringA"   (ByVal   lpApplicationName   As   String,   ByVal   lpKeyName   As   Any,   ByVal   lpDefault   As   String,   ByVal   lpReturnedString   As   String,   ByVal   lSize   As   Long,   ByVal   lpFileName   As   String)   As   Long  
  Declare   Function   WritePrivateProfileString   Lib   "kernel32"   Alias   "WritePrivateProfileStringA"   (ByVal   lpApplicationName   As   String,   ByVal   lpKeyName   As   Any,   ByVal   lpString   As   Any,   ByVal   lpFileName   As   String)   As   Long  
   
  Public   Function   ReadIniFile(ByVal   strIniFile   As   String,   ByVal   strSection   As   String,   ByVal   strKey   As   String)   As   String  
          Dim   strBuffer   As   String  
          Dim   intPos   As   Integer  
   
          strBuffer   =   Space$(255)  
           
          If   GetPrivateProfileString(strSection,   strKey,   vbNullString,   strBuffer,   255,   strIniFile)   >   0   Then  
                  intPos   =   InStr(strBuffer,   Chr(0))  
                  ReadIniFile   =   Trim(Left(strBuffer,   intPos   -   1))  
          Else  
                  ReadIniFile   =   vbNullString  
          End   If  
  End   Function  
   
  Public   Function   WriteIniFile(ByVal   strIniFile   As   String,   ByVal   strSection   As   String,   ByVal   strKey   As   String,   ByVal   strBuffer   As   String)   As   Boolean  
          Dim   i   As   Long  
           
          WriteIniFile   =   False  
           
          i   =   WritePrivateProfileString(strSection,   strKey,   strBuffer,   strIniFile)  
           
          If   i   <>   0   Then   WriteIniFile   =   True  
           
  End   Function  
  Public   Function   getiniPath(ByVal   Path   As   String)  
                Dim   IniFilename   As   String  
                  If   Right(App.Path,   1)   =   "\"   Then  
                          IniFilename   =   App.Path   &   "cpy.ini"  
                  Else  
                          IniFilename   =   App.Path   &   "\cpy.ini"  
                  End   If  
                  getiniPath   =   IniFilename  
  End   Function  
   
  ini文件里是这么写的  
  [machine]  
  machineNo=2  
  tmpath=d:\  
  [DSN]  
  server=13.1.1.52  
  database=cpy  
  datasource=cpy  
  [User]  
  uid=king  
  passwd=  
  [ybs]  
  bs=06  
  [Admin]  
  uid=sa  
  pwd=119  
  address=10.65.159.101Top

3 楼sutdy(好好学习,天天向上)回复于 2005-10-18 14:05:46 得分 0

不知道如何使用?  
  这个方法是不是要配置odbcTop

4 楼faysky2(出来混,迟早是要还嘀)回复于 2005-10-18 14:35:27 得分 0

不知道如何使用?  
  这个方法是不是要配置odbc  
  ---------------------  
  把读到的数据连成你需要的连接字符串就行了,读写INI文件不用配置odbc  
  Top

相关问题

  • 数据库连接的配置文件~
  • 关于XML的数据库配置文件
  • 怎样用配置文件连接数据库?
  • 数据库连接参数配置文件怎么了?
  • 如何把数据库连接做到配置文件里?
  • 关于jsp的数据库配置文件
  • 请问在PB中如何生成连接数据库的配置文件,急。。。。。
  • 关于使用配置文件维护数据库连接的问题
  • resin里的配置文件里如何设置两个数据库连接?
  • 如何读取下面的配置文件中的数据库连接信息???

关键词

  • 数据库
  • 配置文件
  • byval
  • cpy
  • inifilename
  • ini
  • 配置odbc
  • app
  • section
  • path

得分解答快速导航

  • 帖主:sutdy
  • faysky2
  • cuilei197979

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo