这只是从ini文件里读出数据库链接字符串啊

解决方案 »

  1.   

    这只是从ini文件里读出数据库链接字符串啊up
      

  2.   

    while((temp = sr.ReadLine()) != null)
    {
        Sqlpath+= temp;
    }
    这句怎么解释?
      

  3.   

    循环,按字節讀出並存入Sqlpath
      

  4.   

    即然是ini文件,为什么这样读呢?用API不是很方便吗?
      

  5.   

    循环,按字節讀出並存入Sqlpath
    还是不太明白,初学SQL,麻烦大家了!
      

  6.   

    TO:ypw9910
    怎么用API读取SQL文件?
      

  7.   

    现在都不怎么用ini了。一般都用XML或者注册表。
    LZ与时俱进吧,这样写看着都别扭
      

  8.   

    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
        }
    }
      

  9.   

    谢谢大家,谢谢Oceanson(洋之光)!
    那段读取ini文件的代码是在用 Sharpdevelop 些C#程序的时候,自动生成的语句。