c# 如何写入 ini

来源:百度知道 编辑:UC知道 时间:2024/07/09 01:55:28
我的 conn.ini 如下: 没有标准的语法 就这句,我在连接时已经可以调用
Data Source=(local);Database=设备管理系统;Userid=sa ;PassWord=yd20002000

我想在登陆界面的textBox 对内容进行Data Source=,Database=,等进行更换
在 private void button4_Click(object sender, EventArgs e)里面怎么写啊~ ,共四个TEXT
textBox5.Text;
textBox2.Text;
textBox3.Text;
textBox4.Text;

在做项目过程中,有时需要保存一些简单的配置信息,可以使用xml,也可以使用INI文件。下面是C#中读取INI的方法,相信大部分朋友都使用过这种方式。
INI文件的存储方式如下,
[section]
key=value
key=value
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern uint GetPrivateProfileSection(string lpAppName, IntPtr lpReturnedString, uint nSize, string lpFileName);
private static string ReadString(string section, string key, string def, string filePath)
{
StringBuilder temp = new StringBuilder(1024);
try
{
Get