ASP. NET instance code for MySql database operations, asp. netmysql

Source: Internet
Author: User

ASP. NET instance code for MySql database operations, asp. netmysql

1. Put MySql. Data. dll in the BIN directory. 

2. This is all the source code of aspx. cs. Modify the parameters and run them directly!

using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Login : System.Web.UI.Page {   public static class MySqlHelper   {     public static int ExecuteNonQuery(string connectionString, CommandType commandtype, string commandText)     {       return ExecuteNonQuery(connectionString, commandtype, commandText, null);     }     public static int ExecuteNonQuery(string connectionString, CommandType commandtype, string commandText, params MySqlParameter[] commandParameters)     {       if (string.IsNullOrEmpty(connectionString))       {         throw new Exception("connectionString exception");       }       int result = 0;       MySqlConnection con = null;       try       {         using (con = new MySqlConnection(connectionString))         {           con.Open();           MySqlCommand command = new MySqlCommand(commandText, con);           command.CommandType = commandtype;           result = command.ExecuteNonQuery();         }         return result;       }       catch (Exception ex)       {         throw ex;       }       finally       {         if (con.State == ConnectionState.Open)         {           con.Close();         }       }     }   }   protected void Page_Load(object sender, EventArgs e)   {     string connectionString = "server=localhost;uid=root;pwd=;database=zentaopro;";     LogManage_SqlDate.WriteLog("connectionString=:" + connectionString);     string sql = "insert user(account) values('china2')";     MySqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, sql);     Console.Read();   } } 

The above is a small series of ASP.. NET instance code for MySql database operations. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.