Ich weiß, ADODB ist veraltet und sollte nicht verwendet werden. Wer jedoch doch damit arbeiten muss, kann hier mal weiter lesen.
Namespace:
1 |
using ADODB; |
Typen:
1 2 |
private static Connection AdoCon = new Connection(); private static Recordset rs = new Recordset(); |
Connections:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
public static void ConnectDb(string sql) { try { AccessConnectDb("SELECT * FROM Mandanten_Pfad"); StringBuilder sb = new StringBuilder(); sb.Append("Provider=SQLOLEDB.1;Data Source='"); sb.Append(Accessrs.Fields["Datasource"].Value); sb.Append("'; initial Catalog="); sb.Append(Accessrs.Fields["initialCatalog"].Value); sb.Append(";User ID="); sb.Append(Accessrs.Fields["UserID"].Value); sb.Append(";password="); sb.Append(Accessrs.Fields["Password"].Value); try { AdoCon.Open(sb.ToString()); rs.Open(sql, AdoCon, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1); } catch (Exception) { MessageBox.Show("Bitte die Pfade in der mdb überprüfen"); } AccessCloseDb(); } catch (Exception) { } } public static void CloseDb() { try { rs.Close(); AdoCon.Close(); } catch (Exception) { } } |
Methode zu ArrayList
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public static ArrayList DbGetList(string sql) { SortedList<string, object> tmp = new SortedList<string, object>(); ArrayList list = new ArrayList(); List<string> columns = new List<string>(); ConnectDb(sql); int columnCount = rs.Fields.Count; int count = 0; for (int i = 0; i < columnCount; i++) { columns.Add(rs.Fields[i].Name.ToString()); } while (rs.EOF == false) { foreach (string col in columns) { tmp.Add(col, rs.Fields[col].Value); } list.Add(tmp); tmp = new SortedList<string, object>(); count++; rs.MoveNext(); } CloseDb(); return list; } |
Login