我想从我的响应数据读取器对象中读取列名和类型,因为我需要它来实例化一些对象。我出来了:
using (db.sqlConnection) {
db.sqlConnection.Open();
using (var cmd = new SqlCommand("areaGetStreetTypes", db.sqlConnection)) {
cmd.CommandType = CommandType.StoredProcedure;
using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.KeyInfo)) {
DataTable dt = dr.GetSchemaTable();
foreach (DataRow myField in dt.Rows) {
foreach (DataColumn coloana in dt.Columns) {
string c1 = coloana.ColumnName; //column name ???
string c2 = coloana.GetType().ToString(); //column type ??
Console.WriteLine(c1 + " " + c2);
}
}
}
}
}
但不工作。对于每一列返回我想打印(对于初学者)类似:
id_someID int32
name string
surname string
ssn string
我的代码有什么问题?