错了  ,错了 ,都写成改后的函数啦 ,对不起 
=======================================================================///////////////////////////////原函数,两个参数id ,tablename/////////
public string GetMaxId(string id,string tablename)
{
string str_Key;
string str_Sql="select top 1 "+id+" from "+tablename+" order by "+id+" desc";
if (GetRowCount(str_Sql)==0)
{
str_Key="1";
}
else
{
GetRowRecord(str_Sql);
str_Key=(int.Parse(dr[id].ToString())+1).ToString(); // 获得数据库表key值
}
return str_Key;
}=========我把它改了 ,多加了两个参数 count,countvalue就同不过,是我的select 语句写错了吗 ?=====public string GetMaxId(string id,string tablename,string count,string countvalue)
{
string str_Key;
string str_Sql="select top 1 "+id+" from "+tablename+" where "+count+"="+countvalue+"   order by "+id+" desc";
if (GetRowCount(str_Sql)==0)
{
str_Key="1";
}
else
{
GetRowRecord(str_Sql);
str_Key=(int.Parse(dr[id].ToString())+1).ToString(); // 获得数据库表key值
}
return str_Key;
}

解决方案 »

  1.   

    另外  这个select 语句 不太明白 string str_Sql="select top 1 "+id+" from "+tablename+" order by "+id+" desc";
    //////////////////////
    “top 1” 是什么意思呀 ?
      

  2.   

    select top n [percent]  .. from .. 
    指定只从查询结果集中输出前 n 行。
    如果还指定了 percent,则只从结果集中输出前百分之 n 行。 (0<n<100)
      

  3.   

    那可能是我 加的那句 where 语句 跟top1冲突了 ?我再试...
      

  4.   

    你的Sql没错,看看其他什么地方错了。
      

  5.   

    异常详细信息: System.Data.SqlClient.SqlException: 在关键字 'order' 附近有语法错误。源错误: 
    行 76:  myAdapter = new SqlDataAdapter(str_Sql,myConnection);
    行 77:  ds = new DataSet();
    行 78:  myAdapter.Fill(ds);
    行 79:  }
    行 80:  /// <summary>
     
      

  6.   

    string str_Sql="select top 1 "+id+" from "+tablename+" where "+count+"="+countvalue+"   order by "+id+" desc";
    在这呢
      

  7.   

    public void Fill(string str_Sql)
    {  
    Open();
    myAdapter = new SqlDataAdapter(str_Sql,myConnection);
    ds = new DataSet();
    myAdapter.Fill(ds);
    }
    ================================================================================
    public void Fill(string tabname,string sql)
    {  
    Open();
    myAdapter = new SqlDataAdapter(sql,myConnection);
    ds = new DataSet();
    myAdapter.Fill(ds,tabname);
    }
    -------------------------------------------------------------------------------
    -------------------------------------------------------------------------------
    public int GetRowCount(string str_Sql)
    {
    Fill(str_Sql);
    try
    {
    int count=ds.Tables[0].Rows.Count;
    ds.Clear();
    myConnection.Close();
    return count;
    }
    catch
    {
    ds.Clear();
    myConnection.Close();
    return 0;
    }

    }
    ================================================================================
      

  8.   

    你用response.write(xxxx)输出你的sql的str_Sql看一下字符串
    sql中用于寻找最大值的一般用这个方法
    select max(xx) x from table where xxx order by xx
      

  9.   

    str_Key=(int.Parse(dr[id].ToString())+1).ToString(); // 获得数据库表key值这里的 int.Parse(dr[id].ToString.....是什么意思 ?
      

  10.   

    int.Parse(dr[id].ToString())是将dr[id]这个值转换成int类型。
    你的sql语句是动态生成的,里面用了好多变量,无法确知最终的sql语句是否正确,用tongtianming(金银妖瞳) 说的Response.Write方法将你的sql语句写出来看看,然后用查询分析器运行一下看语法是否正确,或者帖到这里也可以。