I load the data into the DataTable from Access.
When I want to get a column type like this:
newDT.Columns[columnName].DataType.FullName I get the .Net types.
For example, instead of ShotText or LongText, I have string.
Can I somehow get SQL types?
I load the data into the DataTable from Access.
When I want to get a column type like this:
newDT.Columns[columnName].DataType.FullName I get the .Net types.
For example, instead of ShotText or LongText, I have string.
Can I somehow get SQL types?
You cannot get SQL types when data is already loaded into a DataTable , but you can retrieve some information during data loading .
If you use an OleDbDataAdapter to populate a DataTable you will instead need to use an OleDbDataReader and specifically its GetSchemaTable method:
DataTable dt = new DataTable("TableName"); OleDbCommand cmd = new OleDbCommand("select * from TableName", connection); using (OleDbDataReader dr = cmd.ExecuteReader()) { DataTable dtSchema = dr.GetSchemaTable(); //берём из схемы интересующие нас мета-данные foreach (DataRow col in dtSchema.Rows) Console.WriteLine("{0} is {1}({2})", col["ColumnName"], (OleDbType)col["ProviderType"], col["ColumnSize"]); //загружаем данные dt.Load(dr); } I don’t know how useful this can be, but the OleDbDataReader also has a GetDataTypeName method:
using (OleDbDataReader dr = cmd.ExecuteReader()) { DataTable dtSchema = dr.GetSchemaTable(); for (int i = 0; i < dr.FieldCount; i++) Console.WriteLine(dr.GetDataTypeName(i)); dt.Load(dr); } Source: https://ru.stackoverflow.com/questions/504845/
All Articles