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
///
/// 公開方法dbconn,返回資料庫連線
///
///
public sqlconnection dbconn()
catch (exception)
}///
/// 公開屬性errormessage,返回錯誤資訊
///
public string errormessage
}///
/// 根據查詢語句從資料庫檢索資料
///
/// 查詢語句
/// 資料庫連線
/// 有資料則返回dataset物件,否則返回null
public dataset select(string selectstring, sqlconnection sqlconn)
else
trysqldataadapter 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)
finally}}
///
/// 更新資料庫
///
/// update sql語句
/// 資料庫連線
/// 更新成功返回true
public bool update(string updatestring, sqlconnection sqlconn)
///
/// 從資料庫中刪除資料
///
/// delete sql語句
/// 資料庫連線
/// 刪除成功返回true
public bool delete(string deletestring, sqlconnection sqlconn)
///
/// 把資料插入資料庫
///
/// insert sql語句
/// 資料庫連線
/// 插入成功返回true
public bool insert(string insertstring, sqlconnection sqlconn)
///
/// 根據sql語句更新資料庫
///
/// 更新語句
/// 資料庫連線
/// 更新成功則返回true
public bool udidatabase(string udistring, sqlconnection sqlconn)
else
trysqlcommand cmd = new sqlcommand(udistring, conn);
cmd.commandtype = commandtype.text;
intcount = cmd.executenonquery();
return !(intcount < 1);
}catch (exception e)
finally}}
}}-----------------------------
兩種呼叫方法
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)
else
return bret;
}
C 資料庫操作類
using system using system.collections.generic using system.linq using system.web using system.data.oledb using system.data using system.configuration ...
Oracle資料庫操作類(c )
用oracleconnection連線oracle 在web.config中配置 oracle value data source user id password public system.data.oracleclient.oracleconnection cnn 開啟資料庫連線 public...
C 操作mysql資料庫類
標頭檔案 cmysql.h 1 ifndef cmysql h 2 define cmysql h 3 4 include 5 include 6 include 7 include 8 9 using namespace std 10 11 class cmysql 12 26 27 endif ...