我要实现的功能是  取出supportID为1的所有行集合中的goodsN文本字段中的最大值,系统调试时提示val是不可识别的函数,请问各位大大如何解决
 SqlConnection conn;
        conn = new SqlConnection("Server=localhost; Uid=sa;pwd=sa; database=byproduct");
        conn.Open();
   //insert   sql   
        string chek = "select max(Conversion.Val(goodsN)) as b from table where supportID ="1"";        SqlDataAdapter dk = new SqlDataAdapter();  
        dk.SelectCommand = new SqlCommand();
       
        dk.SelectCommand.Connection = conn;
      
        dk.SelectCommand.CommandText = chek;
        DataSet myDataset = new DataSet();
        
        dk.Fill(myDataset, "table");
        string hh = myDataset.Tables["SellingWaste_Info"].Rows[0]["b"].ToString().Trim();

解决方案 »

  1.   

    数据库为Access 用VC++同样的select   max(Val(goodsN))   as   b   from   table   代码可以识别
    但是为什么在C#中不可以呀,先谢谢大家关心了
      

  2.   

    max(cast())可以通过了
    但是
    string   hh 无法读出数值, 估计myDataset.Tables[ "SellingWaste_Info "].Rows[0][ "b "].ToString().Trim()有错;
      

  3.   

    Tables[ "SellingWaste_Info "]
    改为Tables[0]
      

  4.   

    不好意思打错字了myDataset.Tables["table"].Rows[0][   'b '].,这行代码可以验证通过,但是没有b这个字段,因为是虚拟字段,所以sql不认识
      

  5.   

    我想到一个办法先在sql server上加maxb字段,用触发器,当其他字段插入时候,update,maxb字段 ,然后
      用下面的代码,不知可否                SqlDataAdapter   dk   =   new   SqlDataAdapter();     
                    dk.SelectCommand   =   new   SqlCommand(); 
                  
                    dk.SelectCommand.Connection   =   conn; 
                
                    dk.SelectCommand.CommandText   =   chek; 
                    DataSet   myDataset   =   new   DataSet(); 
                    
                    dk.Fill(myDataset,   "table "); 
                    string   hh   =   myDataset.Tables[ "table"].Rows[0][ "maxb "].ToString().Trim();
      

  6.   

    myDataset.Tables["table"].Rows[0]["b"]就可以呀
      

  7.   

    奇怪现在用b没有提示出错,但是hh没有值传入,没有数值显示,会不会是我max(cast(goodsN) as INT)      用法有错? 
      

  8.   

    max(cast(goodsN)   as   INT) 这句没错,我试过了,上面程序没错了,hh可以显示了,谢谢niuniuhuang 
    但是我写成   string chek = "DECLARE @supportor INT select max(cast(goodsN as Int)) as b from table where 供应商ID = @supportor";
    -------中间省略
      SqlParameter parm7 = new SqlParameter("@supportor", SqlDbType.Int);
            parm7.Value = (string)Application["ID"];
    hh就不能通过text文本框显示了
      

  9.   

    也就是说我如何将已知数值的变量a, 将a的值传给@supportor