string sql = "select * from g_grade where archment = '优'";
SqlDataAdapter da = new SqlDataAdapter(sql,con.conn);
da.Fill(ds,"grade");
DataTable dt = ds.Tables["grade"];
foreach (DataRow dr in dt.Rows)
{
if ( dr["archment"] == "优")
dr["archment"] = "90";
}求大家帮忙!
背景:archment列为成绩列,nvarchar方式存储,其中有"优","良","中","及格","不及格",以及数字
目的:作比较,选择同门课成绩最高的记录.
我用的方法是将archment列中值为"优"的数据改为"90","良"的数据改为"80",以方便做比较.现在红色字体部分,值为false,IF里面的语句无法执行.请帮忙看看.如果谁有更好的为成绩比大小的方法,小弟感激不尽,另有加分.
SqlDataAdapter da = new SqlDataAdapter(sql,con.conn);
da.Fill(ds,"grade");
DataTable dt = ds.Tables["grade"];
foreach (DataRow dr in dt.Rows)
{
if ( dr["archment"] == "优")
dr["archment"] = "90";
}求大家帮忙!
背景:archment列为成绩列,nvarchar方式存储,其中有"优","良","中","及格","不及格",以及数字
目的:作比较,选择同门课成绩最高的记录.
我用的方法是将archment列中值为"优"的数据改为"90","良"的数据改为"80",以方便做比较.现在红色字体部分,值为false,IF里面的语句无法执行.请帮忙看看.如果谁有更好的为成绩比大小的方法,小弟感激不尽,另有加分.
nvarchar 类型有关系,否则dr["archment"] 是能 取得值得。要仅仅选择同门课成绩最高的记录
那么可以修改sql
select max(成绩),课程 from g_grade group by 课程
dr["archment"] = "90";
dr["archment"].tostring()
要转换字符串
但在Sql中就可以用语句直接修改呀,或者写一个简单的存储过程不就简单了吗?
我试过了,如果用SQL,archment >= 60 会把"不及格""缓考""作弊"等数据也选上.也就是说在nvarchar类型下,根本没法做比较,用SQL语言无法实现上述功能,我用SQL也是将其改变为数字类型后可得.select studid,courid,reupflag,archment into #tmp0 from g_grade
update #tmp0 set archment='0' where archment='缺考' or archment='不及格' or archment='缓考' or archment='作弊'
update #tmp0 set archment='60' where archment='优' or archment='良' or archment='中' or archment='及格'select studid,courid,cast(archment as float) as archment into #tmp3 from #tmp0
select distinct studid,courid,archment into #tmp4 from #tmp3 as a where not exists (select b.* from #tmp3 as b where a.studid=b.studid and a.courid=b.courid and a.archment<b.archment)
order by a.studidselect a.classname,a.studid,a.studname,b.courid,b.courname,b.courcredit,c.archment into #tmp5 from #tmp4 as c,e_student as a,r_course as b
where a.studid=c.studid and b.courid=c.courid and a.classname like 'KT5%' and c.archment<60
order by b.couridselect a.classname,a.studid,a.studname,b.courid,b.courname,b.courcredit,c.archment into #tmp6 from #tmp4 as c,e_student as a,r_course as b
where a.studid=c.studid and b.courid=c.courid and a.classname like 'KT654%' and c.archment<60
order by b.couridselect * from #tmp6 where not exists
(
select * from r_course where r_course.courid= #tmp6.courid and r_course.courid like '00%'
)select * from #tmp5 where not exists
(
select * from r_course where r_course.courid= #tmp5.courid and r_course.courid like '00%'
)以上可实现,但不能动态改变,我打算将其定性为动态控制
即"优"可以设定相当于多少分.暂时来看,如果在内存中将记录改变,并作比较较好.另回二楼:
dr["archment"].ToString() == "优"
无value属性.
尝试可用.
foreach (达式DataRow dr in dt.Rows )
{
if ( dr["archment"].ToString() == drarch["degreename"].ToString() )
dr["archment"] = drarch["realarch"].ToString();
}dt2 11 优 90 2008-9-10 8:09:08 johnbean
12 良 80 2008-9-10 8:09:03 johnbean
13 中 70 2008-9-10 8:08:57 johnbean
14 及格 60 2008-9-10 8:08:50 johnbean
15 不及格 55 2007-7-24 21:45:05 johnbean
16 作弊 0 2000-7-10 9:16:24 johnbean
17 缺考 0 2000-7-10 9:18:04 johnbean
18 缓考 0 2000-7-10 9:18:33 johnbean用这种方法解决了,*_*