毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> net技术 >> 正文

C#读到NULL值时候提示错误“制定转换无效”

更新时间:2014-11-14:  来源:毕业论文

然后当读到某个字段是NULL值时候,系统提示错误“制定转换无效”该怎么修改?
源代码如下
C# code
 
private Yddlinf GetYddlByRow(DataRow row)
        {
            Yddlinf yddl = new Yddlinf();
            yddl.PatientInfoId = (int)row["PatientInfoId"];
            yddl.SeatHoursPerday = (int)row["SeatHoursPerday"];
            yddl.DislikeSport = (string)row["DislikeSport"];
            yddl.FavoriteSportId = (int)row["FavoriteSportId"];
            yddl.SportTimeId = (int)row["SportTimeId"];
            yddl.SportFrequencyPerWeekId = (int)row["SportFrequencyPerWeekId"];
 
            return yddl;
        }


读取代码如下:
C# code

 
 if (IsPostBack == false)
            {
                Id = Int32.Parse(Request.QueryString["id"]);
                YddlMgmt mgmt = new YddlMgmt();
                Yddlinf yddl = mgmt.GetYddlById(Id);
 
                SeatHoursPerday.Text = yddl.SeatHoursPerday.ToString();
                DislikeSport.Text = yddl.DislikeSport.ToString();
                FavoriteSportId.Text = yddl.FavoriteSportId.ToString();
                SportTimeId.Text = yddl.SportTimeId.ToString();
                SportFrequencyPerWeekId.Text = yddl.SportFrequencyPerWeekId.ToString();
                               
            }
几种解决方案:
1. sql解决,  isnull(xxx, 0) as xxx
2. C#中判断 为null时如何处理
3. 将字段改为 int? 类型;

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。