In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "ASP.NET database operation class example analysis", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "ASP.NET database operation class example analysis" this article.
The details are as follows:
Summary description of 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 () {/ TODO: add the constructor logic / public method DBConn here and return the database connection / public SqlConnection DBconn () {string strConn = "Server= (local); Database=GlobalMeetings;Uid=sa;pwd="; try {return new SqlConnection (strConn) } catch (Exception) {return null;}} / expose the property ErrorMessage and return the error message / public string ErrorMessage {get {return strError }} / retrieve data from database according to query statement / query statement / database connection / return DataSet object if there is data, otherwise return null public DataSet Select (string SelectString, SqlConnection sqlConn) {strError = ""; SqlConnection conn; if (sqlConn = = null) {conn = DBconn () } else {conn = sqlConn;} try {/ / if the current state of the database connection is closed, open the connection 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 = "data retrieval failed:" + e.message; return null } finally {if (conn.State! = ConnectionState.Closed) {conn.Close () } / update database / Update Sql statement / database connection / successfully returned true public bool Update (string UpdateString, SqlConnection SqlConn) {return udiDataBase (UpdateString, SqlConn) } / delete data from the database / Delete Sql statement / Database connection / Delete successfully returned true public bool Delete (string DeleteString, SqlConnection SqlConn) {return udiDataBase (DeleteString, SqlConn) } / / insert data into database / Insert Sql statement / database connection / insert successfully returned true public bool Insert (string InsertString, SqlConnection SqlConn) {return udiDataBase (InsertString, SqlConn) } / update the database according to the Sql statement / Database connection / if the update is successful, return 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 = "failed to update database:" + e.Message; return false;} finally {if (conn.State! = ConnectionState.Closed) {conn.Close () The above is all the contents of the article "sample Analysis of ASP.NET Database Operation Class". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.