读取.ini文件里面的连接数据库的代码、读取App.config文件的代码
来源:互联网 发布:家庭理财软件 编辑:程序博客网 时间:2024/06/05 17:40
.ini文件里面的代码:
[sql]
server= 192.168.1.13
uname=sa
pwd=
database=MengYe
[access]
database = weight.mdb
pwd=
[InStorage]
filepath = InStorage.xml
程序里面的代码:
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);
StringBuilder temp = new StringBuilder();
string filepath = Application.StartupPath + @"\Config.ini";
GetPrivateProfileString("sql","server","数据库配置出错!",temp,255,filepath);
string ip = temp.ToString();
GetPrivateProfileString("sql","uname","数据库配置出错!",temp,255,filepath);
string uname = temp.ToString();
GetPrivateProfileString("sql","pwd","数据库配置出错!",temp,255,filepath);
string pwd = temp.ToString();
GetPrivateProfileString("sql","database","数据库配置出错!",temp,255,filepath);
string database = temp.ToString();
String connString = String.Format("server={0};user id={1};pwd={2};database={3}",ip,uname,pwd,database);
SqlConnection conn = new SqlConnection(connString);
读取App.config文件的代码
App.config文件的代码:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add connectionString="server=192.168.1.13;user id=sa;pwd=;database=MengYe" name="sqlserver"/>
<add connectionString="provider=Microsoft.Jet.OLEDB.4.0;Data Source=WeightBill.mdb;Jet oledb:database password=;" name ="access"/>
</connectionStrings>
</configuration>
程序中代码;
加入引用:System.configuration
string connString = ConfigurationManager.ConnectionStrings["sqlServer"].ToString();
- 读取.ini文件里面的连接数据库的代码、读取App.config文件的代码
- C#读取app.config文件中的连接字符串的方法
- 读取文件的代码
- Ini文件的读取
- INI文件的读取
- INI文件的读取
- ini文件的读取
- c代码读取ini文件
- 读取中文文件的代码
- ini文件的读取操作
- 读取自定义的config文件
- app.config的读取
- java读取excel文件里面的标准代码,并自动生成枚举类的java代码
- 读取app.config文件
- C#基本知识 -- App.config文件的配置与读取
- C#基本知识 -- App.config文件的配置与读取
- 读取Config.ini文件内容
- vfp读取config.ini文件
- 在Excel 中用VBA插入图片的方法
- 第二题:一元三次方程求解(NOIP2009测试试题12.08)
- WCF揭秘——自定义绑定
- 典型公司的典型工程师(from http://forum.eet-cn.com)
- Asp.net利用JQuery AJAX实现无刷新评论
- 读取.ini文件里面的连接数据库的代码、读取App.config文件的代码
- PLSQL开发笔记和小结
- eclipse 环境下 FreeMarker 编辑器插件
- Java反射机制
- IFrame取消滚动条并且按内容长度显示mht
- 经典SQL语句大全
- windows 远程RSH调用linux命令
- Know Your Enemy
- EMBED AUDIO