문제

For example, the following code prints "System.Int32", not "int":

string connArgs = "..."; // use your settings here
string query = "SELECT 1";
using (SqlConnection conn = new SqlConnection(connArgs)) {
  conn.Open();
  SqlCommand cmd = new SqlCommand(query, conn);
  using (SqlDataReader reader = cmd.ExecuteReader())
    for (int col = 0; col < reader.VisibleFieldCount; ++col)
      Console.WriteLine(reader.GetFieldType(col));
}

How can I obtain the underlying SQL type, not just its equivalent .NET system type?

도움이 되었습니까?

해결책

You can use a GetDataTypeName method for that:

Gets a string representing the data type of the specified column.

for (int col = 0; col < reader.VisibleFieldCount; ++col) {
    Console.WriteLine(reader.GetDataTypeName(col));
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top