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

新手求助 C#链接access哪里出错了
点击按钮后和卡死一样没反应,代码如下

private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string dir = Directory.GetCurrentDirectory();
            string strcon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + "\\db.mdb";
            using (OleDbConnection con = new OleDbConnection(strcon))
            {
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }
                
              

              DataSet ds = new DataSet();
              OleDbDataAdapter oda = new OleDbDataAdapter("select * from userinfo",con);
              oda.Fill(ds);
              DataTable table = ds.Tables[0];
              DataRowCollection rows=table.Rows;
              for(int i=0;i<rows.Count;i++){
                  DataRow row = rows[i];
                  string username = (string)row["username"];
                  MessageBox.Show(username);
              }
            }
        }