华山轮贱

.NET C# 将 mdb 中数据读为 list<string[]> 其中 path 为数据库地址 ,sql 为查询语句

using System.Data;
using System.Data.OleDb;       



 public static List<string[]> select_list(string path, string sql)
        {

            string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
            OleDbConnection aConnection = new OleDbConnection(connstr);
            OleDbCommand aCommand = new OleDbCommand(sql, aConnection);
            aConnection.Open();
            OleDbDataReader aReader = aCommand.ExecuteReader();
            List<string[]> list1 = new List<string[]>();
            while (aReader.Read())
            {

                int q = aReader.FieldCount;
                string[] li_str1 = new string[q];
                for (int x = 0; x < q; x++)
                {
                    li_str1[x] = aReader[x].ToString();
                }

                list1.Add(li_str1);
            }
            aReader.Close();
            aConnection.Close();
            return list1;
        }

posted on 2015-03-17 16:49  华山轮贱  阅读(263)  评论(0编辑  收藏  举报

导航