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

时间:2023-03-09 04:34:09
.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 = ; x < q; x++)
{
li_str1[x] = aReader[x].ToString();
} list1.Add(li_str1);
}
aReader.Close();
aConnection.Close();
return list1;
}