简体   繁体   中英

What is the best and fast way to get database data type of table field in c# for Postgres?

I have code:

MyDataAdapter.SelectCommand = MySelectCommand;
MyDataAdapter.Fill(MyDataTable);
MyDataGrid.ItemsSource = MyDataTable.DefaultView;
MyDataGrid.Columns.Add(MyDataGridTextColumn1);
MyDataGrid.Columns.Add(MyDataGridTextColumn2);
MyDataGrid.Columns.Add(MyDataGridTextColumn3);
...
MyDataGrid.Columns.Add(MyDataGridTextColumnXXX);

At next step I want to format added columns according to theirs database data type. But there is time limit for building of MyDataGrid. How to do it by the best and fast way?

MyDataTable.Columns[i].DataType.Name;

or

NpgsqlDataReader dr = MyDataAdapter.SelectCommand.ExecuteReader();
dr.GetDataTypeName(i);

where i - index of interesting column

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM