如我有事件public class Manager
{
    #region 基本的增删改查询
    /// <summary>
    /// 取记录信息
    /// </summary>
    public static ManagerInfo GetInfo(params Object[] KeyValue)
    {
        return new ManagerI().GetInfo(KeyValue);
    }
}然后我要根据我的一个查询出来的DataTable来取用这个方法
如我有DataTable
ID
1
2
3
那么取用方法为
Manager.GetInfo(1,2,3)
双如果我的DataTable为
ID 
2
5
8
1
5
8
那么就为
Manager.GetInfo(2,5,8,1,5,8)
也就是根据DataTable的行内容去执行这个方法
但代码要怎么来写呢,可把我头疼得
我现在是用写N个重载的方法来写如OO.GetInfo(int Key)
{
   return Manager.Getinfo(Key);
}
OO.GetInfo(int Key, int Key2)
{
   return Manager.Getinfo(Key,Key2);
}
OO.GetInfo(int Key,i nt Key2, int Key3)
{
   return Manager.Getinfo(Key,Key2,Key3);
}
...
然后在执行的时候用
if(dt.Rows.Count==1)
{
   OO.Getinfo(key)
}
else if(dt.Rows.Count==1)
{
   OO.Getinfo(key,key2)
}
else ...虽然现在我写了10多个这样的重载,可以解决我现在的需票,
但要是有20+的行的话我的这种方法肯定是不行的啦(出错找不到合式的方法)
所以大家看看我这里要怎么来来
--------------------------------------DataTable dt = OO.GetDataTable()
???
Manager.GetInfo(???)
谢谢

解决方案 »

  1.   

    愚笨方法之一:
    给函数再加一个int型的参数,利用查出来的个数:rows.count来对其赋值。
      

  2.   

    public static ManagerInfo GetInfo(int i,params Object[] KeyValue)
        {
            return new ManagerI().GetInfo(i,KeyValue);
        }
    ManagerI().GetInfo(i,KeyValue)这个函数同样有两个参数。
      

  3.   

    RE: 楼上的和楼下的
    在这里 这个方法是不能更改的 绝对不能改public class Manager
    {
        #region 基本的增删改查询
        /// <summary>
        /// 取记录信息
        /// </summary>
        public static ManagerInfo GetInfo(params Object[] KeyValue)
        {
            return new ManagerI().GetInfo(KeyValue);
        }

      

  4.   

    RE:zhuanshen712 
    你的那样的写法是不行的,那样写没有什么意思啊 和我原来的是一样的
      

  5.   

    似乎是传入主键获取记录的方法:
    select * from table where id in ('1','2','5','8')
    按你的思路也是object[]传入后,进行循环,逐条获取加载到datatable
    怎么会用重载这么麻烦
      

  6.   

    RE:楼上的都错了
    我的是:似乎是传入主键获取记录的方法:
    但是不是像上面的:select   *   from   table   where   id   in   ('1','2','5','8') 
    大家不要想太多,主要实现我上面的方法,可能我的DataTable写成这样大家误解了
    那我得新说一下
    DataTable要以如下形貌
    ID ID2 ID3
    1  2    5ID ID2 ID3  ID4
    1  2   5    8我生成的SQL语句为Select * from table where id=1 and id=2 and id=5 这样的大家只要帮我想一下怎么根据上面这样的数据来引用我的
    public static ManagerInfo GetInfo(params Object[] KeyValue)谢谢
      

  7.   

    Select   *   from   table   where   id=1   and   id=2   and   id=5   你这个条件永远都是false
      

  8.   

    你可不可以不用sql代码传嘛,用CS来转也可以撒
      

  9.   

    有点不明白你的意思 你是不是 想根据 Id的值来动态的生成SQL的where条件?你的那个非静态的GetInfo能改吗?
      

  10.   

    我生成的SQL语句为Select   *   from   table   where   id=1   and   id=2   and   id=5   这样的
    ---------------------------
    这个语句...暴寒...
      

  11.   

    Select       *       from       table       where       id1=1       and       id2=2       and       id3=5 
    **************
    应该是这样撒,估计比较粗心,不过问题不描述清楚大家也不好帮忙啊