SQL链接代码 这只是从ini文件里读出数据库链接字符串啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这只是从ini文件里读出数据库链接字符串啊up while((temp = sr.ReadLine()) != null) { Sqlpath+= temp; }这句怎么解释? 循环,按字節讀出並存入Sqlpath 即然是ini文件,为什么这样读呢?用API不是很方便吗? 循环,按字節讀出並存入Sqlpath还是不太明白,初学SQL,麻烦大家了! TO:ypw9910怎么用API读取SQL文件? 现在都不怎么用ini了。一般都用XML或者注册表。LZ与时俱进吧,这样写看着都别扭 aming1102() ypw9910 的意思是把整个sql连接写在ini文件的一个属性里 一次性读出,而对ini的读写有专门的API不需要用StreamReader去模拟循环。下面我给出我的IniHelper类 封装了对Ini的操作我一直用的,很方便。另sqlConnectionString通常也放在xml配置文件中,这个目前比较流行。如果放在web.config中.net也提供了访问类using System;using System.IO;using System.Runtime.InteropServices;using System.Text;namespace UnifiedUtility.INI{ /// <summary> /// This class is used to access ini file. /// </summary> public static class IniFileHelper { #region private fields [DllImport("kernel32")] private static extern int GetPrivateProfileInt( string lpAppName, string lpKeyName, int nDefault, string lpFileName); [DllImport("kernel32")] private static extern int GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName); [DllImport("kernel32")] private static extern bool WritePrivateProfileString( string lpAppName, string lpKeyName, string lpString, string lpFileName); #endregion #region public fields public static int ReadInt(string fileName, string section, string key, int def) { return GetPrivateProfileInt(section, key, def, fileName); } public static string ReadString(string fileName, string section, string key, string def) { StringBuilder temp = new StringBuilder(1024); GetPrivateProfileString(section, key, def, temp, 1024, fileName); return temp.ToString(); } public static void WriteInt(string fileName, string section, string key, int iVal) { WritePrivateProfileString(section, key, iVal.ToString(), fileName); } public static void WriteString(string fileName, string section, string key, string strVal) { WritePrivateProfileString(section, key, strVal, fileName); } public static void DelKey(string fileName, string section, string key) { WritePrivateProfileString(section, key, null, fileName); } public static void DelSection(string fileName, string section) { WritePrivateProfileString(section, null, null, fileName); } #endregion }} 谢谢大家,谢谢Oceanson(洋之光)!那段读取ini文件的代码是在用 Sharpdevelop 些C#程序的时候,自动生成的语句。 bmp图像写入到现有的avi文件 Setup Factory 如何自定义窗体 表格中的排版问题? 顺序播放图片 多线程问题,急! object 用上后不能用JS控制弹出窗口 HttpWebRequest GetResponse 问题(急) 在WinForm中的DataGrid在可以修改的时候不显示FOOTER呢? 用c#编window应用程序来读写xml文件里的客户端配置信息 vb.net函数转成C# 关于限制鼠标区域的问题 双向绑定
{
Sqlpath+= temp;
}
这句怎么解释?
还是不太明白,初学SQL,麻烦大家了!
怎么用API读取SQL文件?
LZ与时俱进吧,这样写看着都别扭
ypw9910 的意思是把整个sql连接写在ini文件的一个属性里 一次性读出,而对ini的读写有专门的API不需要用StreamReader去模拟循环。
下面我给出我的IniHelper类 封装了对Ini的操作
我一直用的,很方便。另sqlConnectionString通常也放在xml配置文件中,这个目前比较流行。如果放在web.config中.net也提供了访问类using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;namespace UnifiedUtility.INI
{
/// <summary>
/// This class is used to access ini file.
/// </summary>
public static class IniFileHelper
{
#region private fields [DllImport("kernel32")]
private static extern int GetPrivateProfileInt(
string lpAppName, string lpKeyName,
int nDefault, string lpFileName);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string lpAppName, string lpKeyName,
string lpDefault, StringBuilder lpReturnedString,
int nSize, string lpFileName);
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(
string lpAppName, string lpKeyName,
string lpString, string lpFileName); #endregion
#region public fields public static int ReadInt(string fileName, string section, string key, int def)
{
return GetPrivateProfileInt(section, key, def, fileName);
} public static string ReadString(string fileName, string section, string key, string def)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(section, key, def, temp, 1024, fileName);
return temp.ToString();
} public static void WriteInt(string fileName, string section, string key, int iVal)
{
WritePrivateProfileString(section, key, iVal.ToString(), fileName);
} public static void WriteString(string fileName, string section, string key, string strVal)
{
WritePrivateProfileString(section, key, strVal, fileName);
} public static void DelKey(string fileName, string section, string key)
{
WritePrivateProfileString(section, key, null, fileName);
} public static void DelSection(string fileName, string section)
{
WritePrivateProfileString(section, null, null, fileName);
} #endregion
}
}
那段读取ini文件的代码是在用 Sharpdevelop 些C#程序的时候,自动生成的语句。