日期:2014-05-17  浏览次数:20858 次

从config文件中读取数据
本帖最后由 yuanhaosh 于 2012-11-23 10:20:45 编辑 从config文件中读取数据在textbox中相对应的位置显示出来,
当config文件中有一两个一个一个取值还好,几十个一个一个取值不科学啊例如下边的
Sqlconnwords.Text = ConfigurationManager.ConnectionStrings["Sqlconnwords"].ToString();
            PrimaryRecApIP.Text = ConfigurationManager.AppSettings["PrimaryRecApIP"];
            PrimaryRecApPort.Text = ConfigurationManager.AppSettings["PrimaryRecApPort"];
            BackupRecApIP.Text = ConfigurationManager.AppSettings["BackupRecApIP"];
            SQWords.Text = ConfigurationManager.AppSettings["SQWords"];
            BackupRecApPort.Text = ConfigurationManager.AppSettings["BackupRecApIP"];
            LocalIp.Text = ConfigurationManager.AppSettings["BackupRecApIP"];
            LocalPort.Text = ConfigurationManager.AppSettings["BackupRecApIP"];
            MaxRetry.Text = ConfigurationManager.AppSettings["MaxRetry"];
            DelayTime.Text = ConfigurationManager.AppSettings["DelayTime"];
            BatchCount.Text = ConfigurationManager.AppSettings["BatchCount"];
            resetTimePicker.Text = ConfigurationManager.AppSettings["resetTimePicker"];
            disconTimePicker.Text = ConfigurationManager.AppSettings["disconTimePicker"];
            NodeName.Text = ConfigurationManager.AppSettings["NodeName"];
            LogType.Text = ConfigurationManager.AppSettings["LogType"];
            RecordLength.Text = ConfigurationManager.AppSettings["RecordLength"];
            MarketType.Text = ConfigurationManager.AppSettings["MarketType"];
            LogPath.Text = ConfigurationManager.AppSettings["LogPath"];
            DataPath.Text = ConfigurationManager.AppSettings["DataPath"];

将下边的如何改能赋给xx.text???
Dictionary<string, string> dict = new Dictionary<string, string>();

                foreach (string key in ConfigurationManager.AppSettings.AllKeys)

                    dict.Add("key.Text", ConfigurationManager.AppSettings[key]);//该怎么将值传递

------最佳解决方案--------------------
config是XML的,直接加载到内存表里,再时行循环付值。这样只需要和物理文件交换一次。
------其他解决方案--------------------
dict.Add(key+".Text", ConfigurationManager.AppSettings[key]);
------其他解决方案--------------------