winform程序,表中的数据是:1和2,int型,1代表停车中,2代表已经离开。
我想在datagridview上 1显示为“停车中”,2显示为“已离开”下面的sql vs提示我"')'"附近有语法错误。请问各位老大什么地方错了呢?
if (tb_card_id.Text == "")
            {
                if (class_type == 0)
                {
                    sql_str = "select car_fee_id as 交易流水号 ,car_fee_nums as 会员卡号,
(case car_fee_flag when 1 then '停车中' when 2 then '已离开')as 卡状态 
from car_park_fee order by car_fee_id desc";
                }
           }SqlConnection conn = new SqlConnection(fee_conn.sql_conn());
                SqlCommand cmd = new SqlCommand(sql_str, conn);
                find_do = new SqlDataAdapter();
                find_do.SelectCommand = cmd;
                ds = new DataSet();
                try
                {
                    find_do.Fill(ds, "rs");
                    d_report.Visible = true;
                }
                catch (System.Exception sqler)
                {
                    MessageBox.Show("数据库不存在或用户名密码错误!", sqler.Message);
                    return;
                }
                d_report.DataSource = ds.Tables["rs"];
                

解决方案 »

  1.   

    不会写SQL的菜鸟,真是伤不起,有木有!!!!!!
      

  2.   

    '已离开')as 卡状态 
    '已离开')  as 卡状态 
    加个空格
      

  3.   

    string   sql_str = @"select car_fee_id as 交易流水号 ,car_fee_nums as 会员卡号,
    (case car_fee_flag when 1 then '停车中' when 2 then '已离开') as 卡状态 
    from car_park_fee order by car_fee_id desc";
      

  4.   

    case car_fee_flag when 1 then '停车中' when 2 then '已离开' end
      

  5.   

    case car_fee_flag when 1 then '停车中' when 2 then '已离开' else '为止' end
    注意end不要漏了
      

  6.   


    其实照您平时的思路,您应该说:“SQL都过时了,你怎么还用,现代编程不用SQL,不用循环,现代编程靠打飞机”
      

  7.   

    http://topic.csdn.net/u/20090304/15/e827ea69-3d56-4557-abae-d5701ee24330.html