心情好,散点源代码玩
1、大数据量分页
public IDataReader GetCurrentDataReader(string tableName,string columns,string PK,int pageSize,int currentPageIndex,string condition,bool desc)
{
this.Mycomm_Init();//初始化
this.reader_Close();//先关闭
string sql;
if(desc)
{
sql="select "+columns+" from "+tableName+" where "+PK+" in (select top "+pageSize.ToString()+" "+PK+" from "+tableName+" where "+PK+" in(select top "+(pageSize*(currentPageIndex+1)).ToString()+" "+PK+" from "+tableName+" where "+condition+" order by "+PK+" Desc) order by "+PK+") order by "+PK+" Desc";
}
else
{
sql="select "+columns+" from "+tableName+" where "+PK+" in (select top "+pageSize.ToString()+" "+PK+" from "+tableName+" where "+PK+" in(select top "+(pageSize*(currentPageIndex+1)).ToString()+" "+PK+" from "+tableName+" where "+condition+" order by "+PK+") order by "+PK+" desc) order by "+PK;
}
this.Mycomm.CommandText=sql;
this.Myconn_Open();//打开连接
this.reader=this.Mycomm.ExecuteReader();
return this.reader;
}
2、HashTable在ADO.NET的巧妙使用方法
public virtual bool TableRow_Add(Hashtable ht,string table_name)
{
ClearTable(table_name);//确保不存在table_name
this.Mya_Build("select * from "+table_name+" where 1=2", table_name);//构造DataAdapter(mya)和填充DataSet(ds)
DataRow Mydr= this.ds.Tables[table_name].NewRow();
IDictionaryEnumerator Mycollection = ht.GetEnumerator();
while(Mycollection.MoveNext())
{
Mydr[Mycollection.Key.ToString()] = MyStr.GetDBValue(Mycollection.Value);
}
this.ds.Tables[table_name].Rows.Add(Mydr);
mya.Update(ds,table_name);
return true;
}
感兴趣的朋友可以根据这个做出TableRow_Update
使用的时候很简单
Hashtable ht=new Hashtable();
ht.Add("FirstName","xhan");
ht.Add("FirstName","2000");
ht.Add("Photo",MyByte);//图片也可
TableRow_Add(ht,"Employees");
特别适合多层开发
牵扯到事务的话,可以继承ServicedComponent,使用自动事务
这两个东西我在很多项目使用,可提高开发效率,有什么问题可以联系我