ODBC et CSharp
De Banane Atomic
Aller à la navigationAller à la recherche
Connection and query
Nuget package: System.Data.Odbc
// use an ODBC DSN name using var odbcConnection = new OdbcConnection("DSN=MyConnection"); var odbcDataAdapter = new OdbcDataAdapter("SELECT * FROM table WHERE validity_date < ?", odbcConnection); odbcDataAdapter.SelectCommand.Parameters.Add("@date", OdbcType.DateTime).Value = maxLimitDate; var dataTable = new DataTable(); odbcConnection.Open(); odbcDataAdapter.Fill(dataTable); Console.WriteLine(string.Join("\t,\t", dataTable.Columns.Cast<DataColumn>().Select(x => x.ColumnName))); Console.WriteLine(string.Join("\n", dataTable.AsEnumerable().Select(x => string.Join("\t,\t", x.ItemArray))); |
Get the table names
var tableNames = odbcConnection.GetSchema("Tables") .AsEnumerable() .Where(r => r.Field<string>("TABLE_TYPE") == "TABLE") .Select(x => x.ItemArray[2]); Console.WriteLine(string.Join("\n", tableNames)); |