|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我之所以想学。NET,是因为一直觉的BILLGATES好厉害,希望有一天能去微软,虽然现在还距离遥远,呵呵:)access|asp.net|会见|数据模仿之前搜集的一个典范sqlserver数据会见类,稍做修正。
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;
///<summary>
///DataAccess的择要申明
///</summary>
publicclassDataAccess
{
protectedstaticOleDbConnectionconn=newOleDbConnection();
protectedstaticOleDbCommandcomm=newOleDbCommand();
publicDataAccess()
{
//init
}
privatestaticvoidopenConnection()
{
if(conn.State==ConnectionState.Closed)
{
conn.ConnectionString=@"Provider=Microsoft.Jet.OleDb.4.0;DataSource="+ConfigurationManager.AppSettings["myconn"];//web.config文件里设定。
comm.Connection=conn;
try
{
conn.Open();
}
catch(Exceptione)
{thrownewException(e.Message);}
}
}//翻开数据库
privatestaticvoidcloseConnection()
{
if(conn.State==ConnectionState.Open)
{
conn.Close();
conn.Dispose();
comm.Dispose();
}
}//封闭数据库
publicstaticvoidexcuteSql(stringsqlstr)
{
try
{
openConnection();
comm.CommandType=CommandType.Text;
comm.CommandText=sqlstr;
comm.ExecuteNonQuery();
}
catch(Exceptione)
{
thrownewException(e.Message);
}
finally
{closeConnection();}
}//实行sql语句
publicstaticOleDbDataReaderdataReader(stringsqlstr)
{
OleDbDataReaderdr=null;
try
{
openConnection();
comm.CommandText=sqlstr;
comm.CommandType=CommandType.Text;
dr=comm.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
try
{
dr.Close();
closeConnection();
}
catch{}
}
returndr;
}//前往指定sql语句的OleDbDataReader工具,利用时请注重封闭这个工具。
publicstaticvoiddataReader(stringsqlstr,refOleDbDataReaderdr)
{
try
{
openConnection();
comm.CommandText=sqlstr;
comm.CommandType=CommandType.Text;
dr=comm.ExecuteReader(CommandBehavior.CloseConnection);
}
catch
{
try
{
if(dr!=null&&!dr.IsClosed)
dr.Close();
}
catch
{
}
finally
{
closeConnection();
}
}
}//前往指定sql语句的OleDbDataReader工具,利用时请注重封闭
publicstaticDataSetdataSet(stringsqlstr)
{
DataSetds=newDataSet();
OleDbDataAdapterda=newOleDbDataAdapter();
try
{
openConnection();
comm.CommandType=CommandType.Text;
comm.CommandText=sqlstr;
da.SelectCommand=comm;
da.Fill(ds);
}
catch(Exceptione)
{
thrownewException(e.Message);
}
finally
{
closeConnection();
}
returnds;
}//前往指定sql语句的dataset
publicstaticvoiddataSet(stringsqlstr,refDataSetds)
{
OleDbDataAdapterda=newOleDbDataAdapter();
try
{
openConnection();
comm.CommandType=CommandType.Text;
comm.CommandText=sqlstr;
da.SelectCommand=comm;
da.Fill(ds);
}
catch(Exceptione)
{
thrownewException(e.Message);
}
finally
{
closeConnection();
}
}//前往指定sql语句的dataset
publicstaticDataTabledataTable(stringsqlstr)
{
DataTabledt=newDataTable();
OleDbDataAdapterda=newOleDbDataAdapter();
try
{
openConnection();
comm.CommandType=CommandType.Text;
comm.CommandText=sqlstr;
da.SelectCommand=comm;
da.Fill(dt);
}
catch(Exceptione)
{
thrownewException(e.Message);
}
finally
{
closeConnection();
}
returndt;
}//前往指定sql语句的datatable
publicstaticvoiddataTable(stringsqlstr,refDataTabledt)
{
OleDbDataAdapterda=newOleDbDataAdapter();
try
{
openConnection();
comm.CommandType=CommandType.Text;
comm.CommandText=sqlstr;
da.SelectCommand=comm;
da.Fill(dt);
}
catch(Exceptione)
{
thrownewException(e.Message);
}
finally
{
closeConnection();
}
}//前往指定sql语句的datatable
publicstaticDataViewdataView(stringsqlstr)
{
OleDbDataAdapterda=newOleDbDataAdapter();
DataViewdv=newDataView();
DataSetds=newDataSet();
try
{
openConnection();
comm.CommandType=CommandType.Text;
comm.CommandText=sqlstr;
da.SelectCommand=comm;
da.Fill(ds);
dv=ds.Tables[0].DefaultView;
}
catch(Exceptione)
{
thrownewException(e.Message);
}
finally
{
closeConnection();
}
returndv;
}
//前往指定sql语句的dataview
}
在VC.net的版本上,为了让C++运行在.NETFramework中,微软为C++引进了托管,就是托管C++(ManagedC++),这个根本就没有流行起来,自托管C++产生以后就没有收到过好评。 |
|