qq_40750668 2019-09-30 09:21 采纳率: 0%
浏览 743

c# ConfigurationManager.AppSettings取不到值?? 命名空间加了using System.Configuration;,引用也加了,config文件也没碰

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace WindowsFormsApplication1
{
public partial class Frm_1 : Form
{
public Frm_1()
{
InitializeComponent();
string str;
str = ConfigurationManager.AppSettings[""];
if (str == null)
MessageBox.Show("str为空");
this.Text = str;

    }

    private void button1_Click(object sender, EventArgs e)
    {
        string str1;
        str1 = ConfigurationManager.AppSettings["User"];
        MessageBox.Show( str1);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        MessageBox.Show("窗体正在加载");
    }

    private void Frm_1_FormClosing(object sender, FormClosingEventArgs e)
    {
        MessageBox.Show("正在关闭窗口,是否退出?");

    }
}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-09-30 09:27
    关注

    str = ConfigurationManager.AppSettings[""];
    这里写的是哪个键?

    在你的 应用程序名.config (不是应用程序.vshost.config) 里面打开,内容检查下,配置项有没有

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿