max() returns an integer, tryint n = (int)mycommand.ExecuteScalar();

解决方案 »

  1.   

    to saucer:
    不行啊,还是一样的错,我的inside_number是nchar型的。
      

  2.   

    ok, try this:
    object o = mycommand.ExecuteScalar();
    Response.Write(o.GetType().Name);what do you see?
      

  3.   

    to saucer:
    结果是DBNull,是什么问题,该怎么解决?
      

  4.   

    to saucer:
    如果number里有匹配的话,就是原来不错的情况,返回是string.
      

  5.   

    用object o取得返回值的话,接下来怎么判断?我用if (o==null)好象不对。
      

  6.   

    string tmp;
    object obj = mycommand.ExecuteScalar();
    if(obj!=null)
       tmp = (string)obj;conn.Close();
      

  7.   

    mycommand.CommandText="select aa=MAX(inside_number) from device where category!='0' and number='"+DropDownList1.SelectedItem.Value+"'";
    conn.Open();
    n=(string)mycommand.ExecuteScalar();
    conn.Close();
      

  8.   

    if 里怎么写,我用o.ToString()==null,不对啊,我用if (o.GetType().Name=="DBNull")可以,可总觉得不是很好,有更好的办法吗?
      

  9.   

    string tmp;
    object obj = mycommand.ExecuteScalar();
    if(obj!=null)
       tmp = obj.ToString();conn.Close();
      

  10.   

    或者用
    n=(string)mycommand.ExecuteScalar();
    但将其放到try catch中
      

  11.   

    object o = mycommand.ExecuteScalar();
    string n = o is DBNull ? "PutWhateverHere" : (string)o;