Xaml解析异常未处理 [英] Xaml Parse Exception unhandled

查看:125
本文介绍了Xaml解析异常未处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试连接到Access数据库2007和WPF2010.

我收到一个异常,知道未处理XAML分析异常.对与指定绑定约束匹配的"Login_Details.MainWindow"类型的构造函数的调用引发了异常Line Number.3和Line Number.9位置.

Hi,

I am trying to connect to the access database 2007 and WPF 2010.

I am getting an exception know XAML Parse Exception was unhandled .The invocation of the constructor on type ''Login_Details.MainWindow'' that matches specified binding constraints threw an exception Line Number.3 and Line Number.9 position.

public MainWindow()
        {
            InitializeComponent();
            connection();
        }
        public void connection()
        {
            string connectionString = null;
            OleDbConnection cnn;
            OleDbCommand cmd;
            string sql = null;
            connectionString = "@Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\SR010\\Documents\\Login.accdb";
            sql = "Select * from Login";
            cnn = new OleDbConnection(connectionString);
            try
            {
                cnn.Open();
                MessageBox.Show("Connection Opened");
                cmd = new OleDbCommand(sql, cnn);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                cnn.Close();
                MessageBox.Show("Execute Non Query in OleDbConnection executed !!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot open connection !" + ex.ToString());
            }
        }
    }
}


请提出必须要做的事情

在此先感谢


Please suggest what has to be done

Thanks in advance

推荐答案

您无法在构造函数中创建与数据库的连接.我的调试器告诉我
You cann''t create a connection to a database in the constructor. My debugger told me there''s a error in the line
cnn = new OleDbConnection(connectionString);


因此,您需要在加载窗口时或在单击按钮时创建一个连接,而不是在构造函数中.


So, you need to create a connection when the window is loaded, or on a button click, but not in the constructor.


这篇关于Xaml解析异常未处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆