如我有事件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(???)
谢谢
{
#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(???)
谢谢
给函数再加一个int型的参数,利用查出来的个数:rows.count来对其赋值。
{
return new ManagerI().GetInfo(i,KeyValue);
}
ManagerI().GetInfo(i,KeyValue)这个函数同样有两个参数。
在这里 这个方法是不能更改的 绝对不能改public class Manager
{
#region 基本的增删改查询
/// <summary>
/// 取记录信息
/// </summary>
public static ManagerInfo GetInfo(params Object[] KeyValue)
{
return new ManagerI().GetInfo(KeyValue);
}
}
你的那样的写法是不行的,那样写没有什么意思啊 和我原来的是一样的
select * from table where id in ('1','2','5','8')
按你的思路也是object[]传入后,进行循环,逐条获取加载到datatable
怎么会用重载这么麻烦
我的是:似乎是传入主键获取记录的方法:
但是不是像上面的: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)谢谢
---------------------------
这个语句...暴寒...
**************
应该是这样撒,估计比较粗心,不过问题不描述清楚大家也不好帮忙啊