ASP.NET操作MySql數(shù)據(jù)庫的實例代碼講解
一、把MySql.Data.dll放到BIN目錄下。
二、這是aspx.cs的全部源碼,修改參數(shù)直接運行即可!
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(); } }
以上所述是小編給大家介紹的ASP.NET操作MySql數(shù)據(jù)庫的實例代碼講解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
MVC使用Log4Net進行錯誤日志記錄學(xué)習(xí)筆記4
這篇文章主要為大家詳細(xì)介紹了MVC使用Log4Net進行錯誤日志記錄,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09Linux上使用Docker部署ASP.NET?Core應(yīng)用程序
這篇文章介紹了使用Docker部署ASP.NET?Core應(yīng)用程序的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03asp.net 驗證字符串是否為純數(shù)字檢測函數(shù)
如何驗證字符串是否為純數(shù)字2010-03-03.NET Core跨平臺串口通訊使用SerialPortStream基礎(chǔ)類庫問題解決
這篇文章介紹了.NET Core跨平臺串口通訊使用SerialPortStream基礎(chǔ)類庫問題解決,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01asp.net音頻轉(zhuǎn)換之.amr轉(zhuǎn).mp3(利用ffmpeg轉(zhuǎn)換法)
AMR轉(zhuǎn)MP3可實現(xiàn)將手機上的AMR錄音轉(zhuǎn)換成流行的MP3格式,以適用更廣泛的應(yīng)用。AMR的體積非常小,適用于存儲在手機中,當(dāng)我們想將在手機上的音頻上傳到網(wǎng)絡(luò),就需要將其轉(zhuǎn)換成MP3等流行的格式,本文就是介紹asp.net利用ffmpeg轉(zhuǎn)換法將.amr轉(zhuǎn).mp3的方法,下面來一起看看吧。2016-12-12