我有一个表,我写了一个类来初始化它。这是课堂的一部分。
this.semester = new TSemester((short)v[0]);
this.course = (int)v[1];
this.xGroup = (byte)v[2];
this.xType = (byte)v[3];
this.subject = (int)v[4];
this.form = (byte)v[5];
this.stdCount = (int)v[6];
this.point = (int)v[7];
this.pointMax = (int)v[8];
this.badCount = (int)v[9];
this.cDate = new TDate((int)v[10]);
this.remark = (string)v[11];
this.options = (int)v[12];
当我尝试用查询填充类时..在行中: this.xGroup =(byte)v [2]; 我有错误指定的强制转换无效 查询是:
select Semester,0,0,0,Subject,0,sum(StdCount),avg(point)
,avg(pointMax),sum(badcount),13940101,'',0 from EvlClass inner join members
on members.srl = Subject where Semester = 13951 and XType=1 and Subject
in(select Srl from Members where Unit in (1101))group by
unit,Semester,Subject
答案 0 :(得分:3)
您的查询返回零的整数字面值,因此无法在应用程序代码中直接转换为字节。您需要返回字节文字0x00
,CAST(0 AS tinyint)
,或使用Convert.ToByte((Int32)v[2]);
将代码中的整数值转换为字节。与其他字节列相同。