格式如下:
[ODBC 32 bit Data Sources]
Xtreme Sample Database 2008=Microsoft Access Driver (*.mdb) (32 ビット)
Xtreme Sample Database 2008 JPN=Microsoft Access Driver (*.mdb) (32 ビット)
DB_TEC_B=SQL Server (32 ビット)
DB_TEC_B_AD=SQL Server (32 ビット)
DB_TEC_B_T=SQL Server (32 ビット)
master=SQL Server (32 ビット)
DB_SX30_B=SQL Server (32 ビット)
DB_SX30_B_AD=SQL Server (32 ビット)
DB_SX30_B_P=SQL Server (32 ビット)
DB_SX30_B1=SQL Server (32 ビット)
DB_SX30_B2=SQL Server (32 ビット)
想通过GetPrivateProfileString函数获取配置文件的所有数据库名字,但是第二个参数是key名称,而.INI文件中key都在等号右边。有什么别的方法可以将所有数据库名称取出来么?
GetPrivateProfileString("ODBC 32 bit Data Sources", "SQL Server (32 ビット)
", "", DBName, 1024, "C:\\WINDOWS\\ODBC.INI");
7 个解决方案
#1
#2
。。。。。。。。。。
#3
木有办法,给日本人干活。。混口饭吃
#4
我找到方法了 取INI文件的指定section的键值
#5
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
/// <summary>
/// INI文件读写类。
/// 张为龙
/// 2008.4
/// </summary>
public class INIFile
{
public string path;
public INIFile(string INIPath)
{
path = INIPath;
}
[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);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
/// <summary>
/// 写INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
public void IniWriteValue(string Section,string Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.path);
}
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <returns></returns>
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 byte[] IniReadValues(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
return temp;
}
/// <summary>
/// 删除ini文件下所有段落
/// </summary>
public void ClearAllSection()
{
IniWriteValue(null,null,null);
}
/// <summary>
/// 删除ini文件下personal段落下的所有键
/// </summary>
/// <param name="Section"></param>
public void ClearSection(string Section)
{
IniWriteValue(Section,null,null);
}
}
#6
C# INI 写入,读取,取得等操作 http://blog.csdn.net/kongwei521/article/details/8115921
#7
恭喜楼主找到正确答案。
[ODBC 32 bit Data Sources] //这个是section
DB_TEC_B=SQL Server //等号左边是key,右边是value
[ODBC 32 bit Data Sources] //这个是section
DB_TEC_B=SQL Server //等号左边是key,右边是value
#1
#2
。。。。。。。。。。
#3
木有办法,给日本人干活。。混口饭吃
#4
我找到方法了 取INI文件的指定section的键值
#5
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
/// <summary>
/// INI文件读写类。
/// 张为龙
/// 2008.4
/// </summary>
public class INIFile
{
public string path;
public INIFile(string INIPath)
{
path = INIPath;
}
[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);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
/// <summary>
/// 写INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
public void IniWriteValue(string Section,string Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.path);
}
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <returns></returns>
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 byte[] IniReadValues(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
return temp;
}
/// <summary>
/// 删除ini文件下所有段落
/// </summary>
public void ClearAllSection()
{
IniWriteValue(null,null,null);
}
/// <summary>
/// 删除ini文件下personal段落下的所有键
/// </summary>
/// <param name="Section"></param>
public void ClearSection(string Section)
{
IniWriteValue(Section,null,null);
}
}
#6
C# INI 写入,读取,取得等操作 http://blog.csdn.net/kongwei521/article/details/8115921
#7
恭喜楼主找到正确答案。
[ODBC 32 bit Data Sources] //这个是section
DB_TEC_B=SQL Server //等号左边是key,右边是value
[ODBC 32 bit Data Sources] //这个是section
DB_TEC_B=SQL Server //等号左边是key,右边是value