如何将Access Db中的数据添加到Treeview

时间:2011-12-28 18:13:34

标签: c# ms-access ado.net treeview

我在Access中有两个表:

客户

  • 1)键(这是自动增量)
  • 2)文本

订单

  • 1)键
  • 2)文本
  • 3)Id_Customer

        OleDbConnection con = new OleDbConnection(strProvider);
        OleDbCommand cmd = new OleDbCommand(strSql, con);
        con.Open();
        OleDbDataReader dr = cmd.ExecuteReader();
        DataTable dtTree = new DataTable();
    
        int columnCount = dr.FieldCount;
    
        for (int i = 0; i < columnCount; i++)
        {
            dataGridView1.Columns.Add(dr.GetName(i).ToString(), dr.GetName(i).ToString());
        }
    
    
        string[] rowData = new string[columnCount];
         while (dr.Read())
         {
             for (int k = 0; k < columnCount; k++)
             {
                 if (dr.GetFieldType(k).ToString() == "System.Int32")
                 {
                     rowData[k] = dr.GetInt32(k).ToString();
                 }
    
                 if (dr.GetFieldType(k).ToString() == "System.String")
                 {
                     rowData[k] = dr.GetString(k);
                 }
             }
    
             dataGridView1.Rows.Add(rowData);
         }
    

如何将这些数据添加到Treeview中?

0 个答案:

没有答案