|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
呵呵,那你就关注微软的招聘信息以及别人的招聘经验啊,还有也不一定去做技术的,你如果真的想去就多了解了解。(其实我的意思是说想到微软做技术是很不容易的。Access数据库操纵类AccessHelper
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.OleDb;
usingSystem.Collections;
///<summary>
///AcceHelper的择要申明
///</summary>
publicstaticclassAccessHelper
{
//数据库毗连字符串
publicstaticreadonlystringconn="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+HttpContext.Current.Request.PhysicalApplicationPath+System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//用于缓存参数的HASH表
privatestaticHashtableparmCache=Hashtable.Synchronized(newHashtable());
///<summary>
///给定毗连的数据库用假定参数实行一个sql命令(不前往数据集)
///</summary>
///<paramname="connectionString">一个无效的毗连字符串</param>
///<paramname="commandText">存储历程称号大概sql命令语句</param>
///<paramname="commandParameters">实行命令所用参数的汇合</param>
///<returns>实行命令所影响的行数</returns>
publicstaticintExecuteNonQuery(stringconnectionString,stringcmdText,paramsOleDbParameter[]commandParameters)
{
OleDbCommandcmd=newOleDbCommand();
using(OleDbConnectionconn=newOleDbConnection(connectionString))
{
PrepareCommand(cmd,conn,null,cmdText,commandParameters);
intval=cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
returnval;
}
}
///<summary>
///用现有的数据库毗连实行一个sql命令(不前往数据集)
///</summary>
///<remarks>
///举例:
///intresult=ExecuteNonQuery(connString,"PublishOrders",newOleDbParameter("@prodid",24));
///</remarks>
///<paramname="conn">一个现有的数据库毗连</param>
///<paramname="commandText">存储历程称号大概sql命令语句</param>
///<paramname="commandParameters">实行命令所用参数的汇合</param>
///<returns>实行命令所影响的行数</returns>
publicstaticintExecuteNonQuery(OleDbConnectionconnection,stringcmdText,paramsOleDbParameter[]commandParameters)
{
OleDbCommandcmd=newOleDbCommand();
PrepareCommand(cmd,connection,null,cmdText,commandParameters);
intval=cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
returnval;
}
///<summary>
///利用现有的SQL事件实行一个sql命令(不前往数据集)
///</summary>
///<remarks>
///举例:
///intresult=ExecuteNonQuery(trans,"PublishOrders",newOleDbParameter("@prodid",24));
///</remarks>
///<paramname="trans">一个现有的事件</param>
///<paramname="commandText">存储历程称号大概sql命令语句</param>
///<paramname="commandParameters">实行命令所用参数的汇合</param>
///<returns>实行命令所影响的行数</returns>
publicstaticintExecuteNonQuery(OleDbTransactiontrans,stringcmdText,paramsOleDbParameter[]commandParameters)
{
OleDbCommandcmd=newOleDbCommand();
PrepareCommand(cmd,trans.Connection,trans,cmdText,commandParameters);
intval=cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
returnval;
}
///<summary>
///用实行的数据库毗连实行一个前往数据集的sql命令
///</summary>
///<remarks>
///举例:
///OleDbDataReaderr=ExecuteReader(connString,"PublishOrders",newOleDbParameter("@prodid",24));
///</remarks>
///<paramname="connectionString">一个无效的毗连字符串</param>
///<paramname="commandText">存储历程称号大概sql命令语句</param>
///<paramname="commandParameters">实行命令所用参数的汇合</param>
///<returns>包括了局的读取器</returns>
publicstaticOleDbDataReaderExecuteReader(stringconnectionString,stringcmdText,paramsOleDbParameter[]commandParameters)
{
//创立一个SqlCommand工具
OleDbCommandcmd=newOleDbCommand();
//创立一个SqlConnection工具
OleDbConnectionconn=newOleDbConnection(connectionString);
//在这里我们用一个try/catch布局实行sql文本命令/存储历程,由于假如这个办法发生一个非常我们要封闭毗连,由于没有读取器存在,
//因而commandBehaviour.CloseConnection就不会实行
try
{
//挪用PrepareCommand办法,对SqlCommand工具设置参数
PrepareCommand(cmd,conn,null,cmdText,commandParameters);
//挪用SqlCommand的ExecuteReader办法
OleDbDataReaderreader=cmd.ExecuteReader(CommandBehavior.CloseConnection);
//扫除参数
cmd.Parameters.Clear();
returnreader;
}
catch
{
//封闭毗连,抛出非常
conn.Close();
throw;
}
}
///<summary>
///前往一个DataSet数据集
///</summary>
///<paramname="connectionString">一个无效的毗连字符串</param>
///<paramname="cmdText">存储历程称号大概sql命令语句</param>
///<paramname="commandParameters">实行命令所用参数的汇合</param>
///<returns>包括了局的数据集</returns>
publicstaticDataSetExecuteDataSet(stringconnectionString,stringcmdText,paramsOleDbParameter[]commandParameters)
{
//创立一个SqlCommand工具,并对其举行初始化
OleDbCommandcmd=newOleDbCommand();
using(OleDbConnectionconn=newOleDbConnection(connectionString))
{
PrepareCommand(cmd,conn,null,cmdText,commandParameters);
//创立SqlDataAdapter工具和DataSet
OleDbDataAdapterda=newOleDbDataAdapter(cmd);
DataSetds=newDataSet();
try
{
//添补ds
da.Fill(ds);
//扫除cmd的参数汇合
cmd.Parameters.Clear();
//前往ds
returnds;
}
catch
{
//封闭毗连,抛出非常
conn.Close();
throw;
}
}
}
///<summary>
///用指定的数据库毗连字符串实行一个命令并前往一个数据集的第一列
///</summary>
///<remarks>
///比方:
///Objectobj=ExecuteScalar(connString,"PublishOrders",newOleDbParameter("@prodid",24));
///</remarks>
///<paramname="connectionString">一个无效的毗连字符串</param>
///<paramname="commandText">存储历程称号大概sql命令语句</param>
///<paramname="commandParameters">实行命令所用参数的汇合</param>
///<returns>用Convert.To{Type}把范例转换为想要的</returns>
publicstaticobjectExecuteScalar(stringconnectionString,stringcmdText,paramsOleDbParameter[]commandParameters)
{
OleDbCommandcmd=newOleDbCommand();
using(OleDbConnectionconnection=newOleDbConnection(connectionString))
{
PrepareCommand(cmd,connection,null,cmdText,commandParameters);
objectval=cmd.ExecuteScalar();
cmd.Parameters.Clear();
returnval;
}
}
///<summary>
///用指定的数据库毗连实行一个命令并前往一个数据集的第一列
///</summary>
///<remarks>
///比方:
///Objectobj=ExecuteScalar(connString,"PublishOrders",newOleDbParameter("@prodid",24));
///</remarks>
///<paramname="conn">一个存在的数据库毗连</param>
///<paramname="commandText">存储历程称号大概sql命令语句</param>
///<paramname="commandParameters">实行命令所用参数的汇合</param>
///<returns>用Convert.To{Type}把范例转换为想要的</returns>
publicstaticobjectExecuteScalar(OleDbConnectionconnection,stringcmdText,paramsOleDbParameter[]commandParameters)
{
OleDbCommandcmd=newOleDbCommand();
PrepareCommand(cmd,connection,null,cmdText,commandParameters);
objectval=cmd.ExecuteScalar();
cmd.Parameters.Clear();
returnval;
}
///<summary>
///将参数汇合增加到缓存
///</summary>
///<paramname="cacheKey">增加到缓存的变量</param>
///<paramname="cmdParms">一个将要增加到缓存的sql参数汇合</param>
publicstaticvoidCacheParameters(stringcacheKey,paramsOleDbParameter[]commandParameters)
{
parmCache[cacheKey]=commandParameters;
}
///<summary>
///找回缓存参数汇合
///</summary>
///<paramname="cacheKey">用于找回参数的关头字</param>
///<returns>缓存的参数汇合</returns>
publicstaticOleDbParameter[]GetCachedParameters(stringcacheKey)
{
OleDbParameter[]cachedParms=(OleDbParameter[])parmCache[cacheKey];
if(cachedParms==null)
returnnull;
OleDbParameter[]clonedParms=newOleDbParameter[cachedParms.Length];
for(inti=0,j=cachedParms.Length;i<j;i++)
clonedParms=(OleDbParameter[])((ICloneable)cachedParms).Clone();
returnclonedParms;
}
///<summary>
///筹办实行一个命令
///</summary>
///<paramname="cmd">sql命令</param>
///<paramname="conn">Sql毗连</param>
///<paramname="trans">Sql事件</param>
///<paramname="cmdText">命令文本,比方:Select*fromProducts</param>
///<paramname="cmdParms">实行命令的参数</param>
privatestaticvoidPrepareCommand(OleDbCommandcmd,OleDbConnectionconn,OleDbTransactiontrans,stringcmdText,OleDbParameter[]cmdParms)
{
//判别毗连的形态。假如是封闭形态,则翻开
if(conn.State!=ConnectionState.Open)
conn.Open();
//cmd属性赋值
cmd.Connection=conn;
cmd.CommandText=cmdText;
//是不是必要用到事件处置
if(trans!=null)
cmd.Transaction=trans;
cmd.CommandType=CommandType.Text;
//增加cmd必要的存储历程参数
if(cmdParms!=null)
{
foreach(OleDbParameterparmincmdParms)
cmd.Parameters.Add(parm);
}
}
}
J2EE比较成熟一点,一些比较出名的企业应用软件都是基于J2EE的。以后的发展就不好说了。不过java比较烦,学.net的话,微软把很多工具都封装好了,学起来可能容易一点。 |
|