日期:2014-05-18 浏览次数:20759 次
select case when 成绩>=60 then '及格' else '不及格' end from 表名
------解决方案--------------------
那就直接判断就可以了啊
------解决方案--------------------
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
private void Bind()
{
string strcn = @"Dsn=ss7server;DataBase=NTP2000;uid=zxt2000;pwd=zxt2000;";
OdbcConnection mycn = new OdbcConnection(strcn);
string sql = "select 学号,case when 成绩>=60 then '及格' else '不及格' end 成绩 from tb_xscj ";
//string sql = "select 学号,case when 成绩>=60 then '及格' else '不及格' end 成绩 from tb_xscj where 学号=110";
mycn.Open();
OdbcDataAdapter myDa = new OdbcDataAdapter(sql, mycn);
DataSet myDs = new DataSet();
myDa.Fill(myDs, "s");
GridView1.DataSource = myDs;
GridView1.DataBind();
}
------解决方案--------------------
for (int i = 0; i < datatable.Rows.Count; i++) { //取出学号和成绩 string num = datatable.Rows[i][0].ToString(); string score = datatable.Rows[i][1].ToString(); //逐行赋值 datagridview1["学号", i].Value = num; datagridview1["成绩", i].Value = score; if (score >= "60") { datagridview1["成绩等级", i].Value = "及格"; } else { datagridview1["成绩等级", i].Value = &q