public List<List<string>> getAccessData(string path) { string conStr = @"Provider=microsoft.ace.oledb.12.0;Data Source=" + path; List<List<string>> list = new List<List<string>>(); DbForAccess dfa = new DbForAccess(conStr); //string sql = "select [Name] from MSysObjects where type=1"; //OleDbDataReader sdrTable = dfa.ReturnDataReader(sql); //sdrTable.Read(); //string tableName = sdrTable[0].ToString(); string sql = "select * from "+"联系人"+" order by 姓"; OleDbDataReader sdr = dfa.ReturnDataReader(sql); while (sdr.Read()) { List<string> line = new List<string>(); if (!string.IsNullOrEmpty(sdr[3].ToString())) { for (int i = 0; i < sdr.FieldCount; i++) { line.Add(sdr[i].ToString().Replace("\0","").Replace(" ", "").Replace("(", "(").Replace(")", ")")); } list.Add(line); } } sdr.Dispose(); return list; }
private void InsertNames(string path, List<List<string>> list) { this.progressBar1.Maximum = list.Count; string conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path; DbForAccess dfa = new DbForAccess(conStr); for (int i = 0; i < list.Count; i++) { StringBuilder sb = new StringBuilder(); sb.Append("insert into phone values ("); for (int j = 0; j < list[i].Count; j++) { sb.Append("'"+list[i][j]+"',"); } //sb.Append("'"+DateTime.Now+"'"); sb = sb.Remove(sb.Length-1,1); sb.Append(")"); if (!dfa.ExeSQL(sb.ToString())) MessageBox.Show("error"); this.progressBar1.Value = i; } SetComplete(); }