zoukankan
html css js c++ java
《ASP.net组件设计》PowerORM的完整代码
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Reflection;
using
Microsoft.ApplicationBlocks.Data;
using
System.Data.SqlClient;
public
partial
class
PowerORM : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
string
strConnection
=
"
Server=127.0.0.1;User ID=sa;Password=qqww;Persist Security Info=True;DataBase=Northwind;
"
;
string
strSQL
=
"
SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]
"
;
IList myList;
using
(SqlDataReader myReader
=
SqlHelper.ExecuteReader(strConnection, CommandType.Text, strSQL))
{
myList
=
myPowerORM.FillHelper.Fill((
new
myPowerORM.Customer()).GetType(), myReader);
}
Response.Write(
"
<pre>
"
);
foreach
(
object
o
in
myList)
{
myPowerORM.Customer c
=
(myPowerORM.Customer)o;
Response.Write(c.CustomerID
+
"
\t
"
+
c.CompanyName
+
"
\t
"
+
c.ContactNameI
+
"
\n<br>
"
);
}
Response.Write(
"
</pre>
"
);
}
}
namespace
myPowerORM
{
public
class
Customer
{
private
string
_customerID, _companyName, _contactName;
[Column(
"
CustomerID
"
)]
public
string
CustomerID
{
get
{
return
_customerID; }
set
{ _customerID
=
value; }
}
[Column(
"
CompanyName
"
)]
public
string
CompanyName
{
get
{
return
_companyName; }
set
{ _companyName
=
value; }
}
[Column(
"
ContactName
"
)]
public
string
ContactNameI
{
get
{
return
_contactName; }
set
{ _contactName
=
value; }
}
public
Customer()
{ }
}
[AttributeUsage(AttributeTargets.Property, Inherited
=
false
, AllowMultiple
=
false
)]
public
class
ColumnAttribute : Attribute
{
private
string
_columnName
=
null
;
public
string
ColumnName
{
get
{
return
_columnName; }
}
public
ColumnAttribute(
string
columnName)
{
_columnName
=
columnName;
}
}
public
class
FillHelper
{
public
static
IList Fill(Type rowType, IDataReader reader)
{
ArrayList dataList
=
new
ArrayList();
while
(reader.Read())
{
object
item
=
Activator.CreateInstance(rowType,
false
);
//
使用与指定参数匹配程度最高的构造函数创建指定类型的实例
foreach
(MemberInfo mi
in
rowType.GetMembers())
{
foreach
(ColumnAttribute attr
in
mi.GetCustomAttributes(
typeof
(ColumnAttribute),
false
))
{
int
index
=
reader.GetOrdinal(attr.ColumnName);
//
在给定列名称的情况下获取列序号
if
(index
!=
-
1
)
{
if
(mi.MemberType
==
MemberTypes.Field)
((FieldInfo)mi).SetValue(item, reader.GetValue(index));
else
if
(mi.MemberType
==
MemberTypes.Property)
((PropertyInfo)mi).SetValue(item, reader.GetValue(index),
null
);
}
}
}
dataList.Add(item);
}
return
dataList;
}
public
FillHelper()
{ }
}
}
查看全文
相关阅读:
AFNetWorking 文件上传 By-H罗
利用系统APP实现导航---By张秀清
项目 和 需求文档 -- 吴欧
键盘弹起及lab时的动态计算高度 --董鑫
NSSet和NSMutableSet
内联函数 在ios中的运用 --黄仁斌
iOS 七大手势之轻拍,长按,旋转手势识别器方法-赵小波
网络技术之BGP
[手游项目3]-3-golang
[手游项目3]-2-git
原文地址:https://www.cnblogs.com/goodspeed/p/191141.html
最新文章
[bzoj2005][Noi2010]能量采集
[bzoj2049][Sdoi2008]Cave 洞穴勘测
[bzoj1787] [Ahoi2008]Meet 紧急集合
[bzoj1038][ZJOI2008]瞭望塔
[bzoj1023][SHOI2008]cactus仙人掌图
[bzoj1086][SCOI2005]王室联邦
[bzoj1055][HAOI2008]玩具取名
redis
spring 结合 redis 例子 (转)
oracle查询所有用户表的表名、主键名称、索引、外键等(转)
热门文章
java程序中的多线程(转)
centos6.4中文输入法安装和切换(转载)
redis缓存的安装和使用(转)
java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.springframework.web.servlet.DispatcherServlet异常
命令行窗口编译执行java
io.File+递归
iOS测试模板
聊天泡泡(仿微信)By-H罗
iOS中通过链接地址打开指定APP并传参 by徐文棋
Copyright © 2011-2022 走看看