日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

INI文件格式及其操作代碼

 浮 生 2009-08-03

INI文件格式及其操作代碼

INI文件格式如下: 
[Database] 
server=wlq 
database=mydatabase 
uid=sa 
pwd=123456

說明:(有4個(gè)key) 
Section為:Database 
Key為:server database uid pwd

/***************代碼******************/ 
using System; 
using System.IO; 
using System.Runtime.InteropServices; 
using System.Text;


namespace Sx_Mdi 
{

/// <summary> 
/// Summary description for Class1. 
/// </summary> 
public class IniFile 

//文件INI名稱 
public string Path;

////聲明讀寫INI文件的API函數(shù) 
[DllImport("kernel32")]

private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);


[DllImport("kernel32")]

private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);


//類的構(gòu)造函數(shù),傳遞INI文件名 
public IniFile(string inipath) 

// 
// TODO: Add constructor logic here 
// 
Path = inipath; 
}

//寫INI文件 
public void IniWriteValue(string Section,string Key,string Value) 

WritePrivateProfileString(Section,Key,Value,this.Path);

}

//讀取INI文件指定 
public string IniReadValue(string Section,string Key) 

StringBuilder temp = new StringBuilder(255); 
int i = GetPrivateProfileString(Section,Key,"",temp,255,this.Path); 
return temp.ToString();

}



}

操作范例:

public static SqlConnection MyConnection() 

string sPath; 
string ServerName,userId,sPwd,DataName;

sPath = GetPath(); 
IniFile ini = new IniFile(sPath); 
ServerName = ini.IniReadValue ("Database","server"); 
userId = ini.IniReadValue ("Database","uid"); 
sPwd = ini.IniReadValue ("Database","pwd"); 
DataName = ini.IniReadValue ("Database","database"); 
string strSql = "server =" + ServerName+";uid ="+ userId +";pwd =;database ="+ DataName; 
    SqlConnection myConn=new SqlConnection(strSql); 
    return myConn; 
}

/***************代碼******************/

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多