我已经读过关于SQL类型映射的文章了,但是我不明白.两者都显示在控制台中的Int16,但当我尝试
f.smallId = dr[0];即使是一个简单的测试
Int16 test=dr[0];不起作用:它现在说dr是一个物体
NpgsqlCommand command = new NpgsqlCommand("select id from database", conn);
NpgsqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr[0].GetType());
foreach (Definitions f in files)
{
Console.WriteLine(f.smallId.GetType());
f.smallId = dr[0];
}
}发布于 2016-03-13 12:53:58
是的,因为 property 返回object,并且没有从object到Int16的隐式会话,但是有一个显式会话。
只需使用;
Int16 test = (Int16)dr[0];还可以使用using语句自动释放命令和适配器。
https://stackoverflow.com/questions/35970434
复制相似问题