In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use ASP.NET to connect to oledb database". In daily operation, I believe many people have doubts about how to use ASP.NET to connect to oledb database. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use ASP.NET to connect to oledb database". Next, please follow the editor to study!
1.ASP.NET database connection class: ClassConn
Using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; namespace zz {/
< summary>/ / A summary description of the ClassConn. / / /
< /summary>Public class conn / / ASP.NET database connection class {public conn () {/ TODO: add constructor logic / /} public SqlConnection connstr; / / connection string public string getconnstr () / / get the connection string {string constr; constr=System.Configuration.ConfigurationSettings.AppSettings ["connstring"]; return constr } public void open () / / Open database {string constr; constr=getconnstr (); connstr=new SqlConnection (constr); connstr.Open ();} public void close () / / close database {connstr.Dispose (); connstr.Close () } public void execsql (string sql) / / execute sql statements {open (); SqlCommand cmd=new SqlCommand (sql,connstr); cmd.ExecuteNonQuery (); close ();} public DataSet dataset (string sql) / / return DataSet object {open (); SqlDataAdapter rs=new SqlDataAdapter (sql,connstr); DataSet ds=new DataSet (); rs.Fill (ds); return ds } public DataView dataview (string sql) / / returns DataView object {DataSet ds=new DataSet (); ds=dataset (sql); DataView dv=new DataView (ds.Tables [0]); return dv;} public SqlDataReader datareader (string sql) / / returns DataReader object {open (); SqlCommand cmd=new SqlCommand (sql,connstr); SqlDataReader dr=cmd.ExecuteReader (); return dr;}
two。 Connect to an oledb database using the ASP.NET database connection class
Using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace xyl {/
< summary>/ / A summary description of the ClassConn. / / /
< /summary>Public class ClassConn {public ClassConn () {/ TODO: add constructor logic / /} public OleDbConnection connstr; public string getconnstr () {string constr; constr= "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + HttpRuntime.AppDomainAppPath+ System.Configuration.ConfigurationSettings.AppSettings ["connstring"]; return constr;} public void OpenDB () {string constr here Constr=getconnstr (); connstr=new OleDbConnection (constr); connstr.Open ();} public void CloseDB () {connstr.Dispose (); connstr.Close ();} public void execsql (string sql) {OpenDB (); OleDbCommand cmd=new OleDbCommand (sql,connstr); cmd.ExecuteNonQuery (); CloseDB () } public DataSet DataSets (string sql) {OpenDB (); OleDbDataAdapter rs=new OleDbDataAdapter (sql,connstr); DataSet ds=new DataSet (); rs.Fill (ds); return ds;} public DataView DataViews (string sql) {DataSet ds=new DataSet (); ds=DataSets (sql); DataView dv=new DataView (ds.Tables [0]); return dv } public OleDbDataReader MyDataReader (string sql) {OpenDB (); OleDbCommand myCom=new OleDbCommand (sql,connstr); OleDbDataReader myreader=myCom.ExecuteReader (); return myreader;} at this point, the study on "how to connect to an oledb database using ASP.NET" is over. I hope you can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.