嗨,我在_obj.Add上看到了这个错误(新的数据).这是我的密码
SqlCommand com = new SqlCommand("sp_get_a", con)
{
CommandType = CommandType.StoredProcedure
};
_obj = new List<n>();
con.Open();
SqlDataReader rdr = com.ExecuteReader();
if (rdr.HasRows)
{
while (rdr.Read())
{
_obj.Add(new data() { Id = rdr.GetInt32(0), na = rdr.GetString(1), Al = rdr.GetString(2), Sc = rdr.GetFloat(3), So = rdr.GetInt32(4), Ta = rdr.GetInt32(5), Ai = rdr.GetInt32(6), Sh = rdr.GetInt32(7) });
}
}
else
{
throw new Exception("rdr don't have any rows");
}
con.Close();我的存储过程
CREATE PROCEDURE sp_get_a作为选择Id,Na,Al,Sc,So,Ta,Ai,Sh从x我没有任何双值,最接近的是Sc(浮子)。所以我尝试了Sc = Convert.ToSingle(rdr.GetFloat(3))。我哪里做错了?编辑-我的模型
public class n
{
public int Id { get; set; }
public string Na { get; set; }
public string Al { get; set; }
public float Sc { get; set; }
public int So { get; set; }
public int Ta { get; set; }
public int Ai { get; set; }
public int Sh { get; set; }
}发布于 2020-06-12 03:55:07
您需要将Sc的数据类型从float更改为double
Server real等效于C# Single,server float等效于C# Double。
你也应该考虑一下@jdweng点
https://stackoverflow.com/questions/62337101
复制相似问题