All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL注入技术和跨站脚本攻击的检测_[SQL,Server教程]
扩展GridView控件(九)——给数据行增加右键菜单_[Asp.Net教程]
SQLServer2005中的XML选项详解(1)_[SQL Server教程]
PHP学习宝典-第八章(一)_[PHP教程]
Ajax实现无刷新三联动下拉框_[Asp.Net教程]
ASP.Net环境下使用Jmail组件发送邮件_[Asp.Net教程]
SQL,Server,索引结构及其使用_[SQL,Server教程]
C#控制语句中的switch语句用法
Delphi在状态栏中显示检查框
ASP连接SQL2000的方法_[SQL,Server教程]
Reading number is top 10 pictures
哥斯达黎加的门将是如何练成的
The world's top ten most beautiful railway station1
锄禾日了几个人?
真正的国产-非模拍 贵在是真实2
China's first snake village1
赵惟依写真1
Household design of gorgeous series
关于海盗的研究2
美女和狗狗1
29 the belle stars after bath figure3
Download software ranking
Tram sex maniac 2 (H) rar bag16
I for your crazy
虚拟机汉化软件
SP3 for SQL2000
Tram sex maniac 2 (H) rar bag1
Such love down(擒爱记)
Professional killers2 data package
Sora aoi‘s film--Lust fan wall
jdk1.5
Boxer vs Yellow4
delv published in(发表于) 2014/1/6 9:04:45 Edit(编辑)
ASP.NET的一个简单的数据操作类_[Asp.Net教程]

ASP.NET的一个简单的数据操作类_[Asp.Net教程]

ASP.NET的一个简单的数据操作类_[Asp.Net教程]

我现在还不会写持久层,就用这种方法加上存储过程用,我感觉还比较爽,希望大家多多指教
public class clsdb
{

public clsdb()
{
//
// TOD 在此处添加构造函数逻辑
//
}
//数据库连接
public static SqlConnection getcn()
{
return (new SqlConnection("server=.;database=web;uid=sa;pwd=123"));
}
//GridView的绑定方法
public static void DataBindGridViewAsTable(GridView Grid,String strsql)
{
SqlConnection cn = clsdb.getcn();
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(strsql,cn);
DataTable td = new DataTable();
da.Fill(td);
Grid.DataSource = td;
Grid.DataBind();
cn.Close();
cn.Dispose();
}
//添加,删除,更新记录的方法
public static void AddDelUpDataBase(String strsql)
{
SqlConnection cn = clsdb.getcn();
cn.Open();
SqlCommand cmd = new SqlCommand(strsql,cn);
cmd.ExecuteNonQuery();
cn.Close();
cn.Dispose();
}
//返回一条记录的方法
public static int select(String strsql)
{
int i = -1;
SqlConnection cn = clsdb.getcn();
cn.Open();
SqlCommand cmd = new SqlCommand(strsql, cn);
i=(int)cmd.ExecuteScalar();
cn.Close();
cn.Dispose();
return i;
}
//返回SqlDataReader 的记录集


public static SqlDataReader SelectDataBase(String strsql)
{
SqlConnection cn = clsdb.getcn();
cn.Open();
SqlCommand cmd = new SqlCommand(strsql,cn);
cmd.CommandType = CommandType.Text;
SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return rd;

}
//绑定DropDownList的方法
public static void DataBindDropDownList(DropDownList drp,string strsql)
{
SqlConnection cn = getcn();
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(strsql,cn);
DataTable td = new DataTable();
da.Fill(td);
drp.DataSource = td;
drp.DataBind();
cn.Close();
cn.Dispose();
}
//绑定DataList的方法
public static void DataBindDataList(DataList list, string strsql)
{
SqlConnection cn = getcn();
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(strsql, cn);
DataTable td = new DataTable();
da.Fill(td);
list.DataSource = td;
list.DataBind();
cn.Close();
cn.Dispose();
}
}


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.