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

Reading number is top 10 articles
SQL,Server处理数据层错误_[SQL,Server教程]
C#,3.0新特性初步研究,Part1:使用隐含类型的本地变量_[Asp.Net教程]
用ASP.NET开发电子商务网站对数据库表的设计_.net资料_编程技术
asp.net,页面事件:顺序与回传_[Asp.Net教程]
利用SQL,Server发邮件_[SQL,Server教程]
也谈,.NET2.0中避免分布式事务_.net资料_编程技术
PHP转到另一网页实现办法一,二,三_[PHP教程]
如何让javascript,操作Cookie_php资料_编程技术
Delphi执行sql server模糊查询
IIS中Sql,server数据库的安全问题_[SQL,Server教程]
Reading number is top 10 pictures
HongMenYan premiere XinLiangGong clairvoyant outfit PK YiFeiLiu2
2012 national geographic daily picture6
Thrilling English baby
China's family planning commission forced abortions 270 million newborns for 30 years
Photographed the passion of the clients and prostitutes in the sex trade picture2
Players in the eyes of a perfect love2
重口味人造肉
Go to the national museum1
29 the belle stars after bath figure1
看到这个手速,决定过年就让我家猫帮我抢红包了。。
Download software ranking
C#与.NET技术平台实战演练
Boxer's Top ten classic battle7
网络管理员第三版
仙剑奇侠传98硬盘WINXP版
都市狐狸姑娘传
Tram sex maniac 2 (H) rar bag14
Boxer vs Yellow1
Tram sex maniac 2 (H) rar bag9
White deer villiage
C++编程教程第三版
delv published in(发表于) 2014/1/10 6:24:50 Edit(编辑)
Asp.net(c#)数据库操作类_[Asp.Net教程]

Asp.net(c#)数据库操作类_[Asp.Net教程]

Asp.net(c#)数据库操作类_[Asp.Net教程]


using System;
using System.Data;
using System.Configuration;
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.Data.SqlClient;
namespace Mysqlserver
{
///


/// SqlServerDataBase 的摘要说明
///

public class SqlServerDataBase
{
private string strError = null;
private int intCount = 0;
public SqlServerDataBase()
{
//
// TOD 在此处添加构造函数逻辑
//
}
///
/// 公开方法DBConn,返回数据库连接
///

///
public SqlConnection DBconn()
{
string strConn = "Server=(local);Database=GlobalMeetings;Uid=sa;pwd=";
try
{
return new SqlConnection(strConn);
}
catch (Exception)
{
return null;
}
}
///
/// 公开属性ErrorMessage,返回错误信息
///

public string ErrorMessage
{
get
{
return strError;
}
}


///


/// 根据查询语句从数据库检索数据
///

/// 查询语句
/// 数据库连接
/// 有数据则返回DataSet对象,否则返回null
public DataSet Select(string SelectString, SqlConnection sqlConn)
{
strError = "";
SqlConnection conn;
if (sqlConn == null)
{
conn = DBconn();
}
else
{
conn = sqlConn;
}
try
{
//若数据库连接的当前状态是关闭的,则打开连接
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
SqlCommand selectCommand = new SqlCommand(SelectString, conn);
selectCommand.CommandType = CommandType.Text;
mySqlDataAdapter.SelectCommand = selectCommand;
DataSet myDS = new DataSet();
mySqlDataAdapter.Fill(myDS);
return myDS;
}
catch (Exception e)
{
strError = "数据检索失败:" + e.Message;
return null;
}
finally
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
}
}
///
/// 更新数据库
///

/// Update Sql语句
/// 数据库连接
/// 更新成功返回true
public bool Update(string UpdateString, SqlConnection SqlConn)
{
return udiDataBase(UpdateString, SqlConn);
}
///
/// 从数据库中删除数据
///

/// Delete Sql语句
/// 数据库连接
/// 删除成功返回true
public bool Delete(string DeleteString, SqlConnection SqlConn)
{
return udiDataBase(DeleteString, SqlConn);
}
///
/// 把数据插入数据库
///

/// Insert Sql语句
/// 数据库连接
/// 插入成功返回true
public bool Insert(string InsertString, SqlConnection SqlConn)
{
return udiDataBase(InsertString, SqlConn);
}
///
/// 根据Sql语句更新数据库
///

/// 更新语句
/// 数据库连接
/// 更新成功则返回true
public bool udiDataBase(string UDIString, SqlConnection SqlConn)
{
strError = "";
SqlConnection conn;
if (SqlConn == null)
{
conn = DBconn();
}
else
{
conn = SqlConn;
}
try
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlCommand cmd = new SqlCommand(UDIString, conn);
cmd.CommandType = CommandType.Text;
intCount = cmd.ExecuteNonQuery();
return !(intCount < 1);
}
catch (Exception e)
{
strError = "更新数据库失败:" + e.Message;
return false;
}
finally
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
}
}
}
}
-----------------------------
两种调用方法
1、 string strUserPsw = UserPsw.Text.Trim();
string UserPassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strUserPsw, "MD5");//md5加密
SqlServerDataBase obj = new SqlServerDataBase();
obj.Insert("insert into asUserInfo (UserName,UserPassword,Question,Answer,CreateTime) values('" + UserName.Text.Trim() + "','" + UserPassword + "','" + Question.Text.Trim() + "','" + Answer.Text.Trim() + "','" + DateTime.Now.ToString() + "' )", null);
2、 private bool IsUsernameExist(string strUsername)
{
bool bRet = true;
SqlServerDataBase db = new SqlServerDataBase();
DataSet ds = db.Select("select * from asUserInfo where UserName = '" + strUsername + "'", null);
if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
{
bRet = false;
}
else
{
bRet = true;
}


return bRet;
}


http://blog.csdn.net/zdyguilong/archive/2007/01/22/1490250.aspx







添加到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.