ASP.NET操作MySql數(shù)據(jù)庫(kù)的實(shí)例代碼講解
一、把MySql.Data.dll放到BIN目錄下。
二、這是aspx.cs的全部源碼,修改參數(shù)直接運(yùn)行即可!
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ù)庫(kù)的實(shí)例代碼講解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
MVC使用Log4Net進(jìn)行錯(cuò)誤日志記錄學(xué)習(xí)筆記4
這篇文章主要為大家詳細(xì)介紹了MVC使用Log4Net進(jìn)行錯(cuò)誤日志記錄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09Linux上使用Docker部署ASP.NET?Core應(yīng)用程序
這篇文章介紹了使用Docker部署ASP.NET?Core應(yīng)用程序的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03淺談.NET中加密和解密的實(shí)現(xiàn)方法分享
這篇文章介紹了.NET中加密和解密的實(shí)現(xiàn)方法,有需要的朋友可以參考一下2013-11-11asp.net 無(wú)刷新翻頁(yè)就是這么簡(jiǎn)單
前兩天看了一個(gè)自定義分頁(yè)控件,和AspNetPager一樣是實(shí)現(xiàn)IPostBackEventHandler接口,不過(guò)簡(jiǎn)潔許多,就想能不能實(shí)現(xiàn)ICallbackEventHandler接口做到無(wú)刷新分頁(yè)呢?想到了就馬上去做,終于,設(shè)想變成了現(xiàn)實(shí)?。?/div> 2010-03-03asp.net 2.0多語(yǔ)言網(wǎng)站解決方法
asp.net 2.0中的App_GlobalResources可以用來(lái)解決本地化的問(wèn)題,程序會(huì)根據(jù)瀏覽器的語(yǔ)言首選項(xiàng)自動(dòng)判斷顯示出本地化的界面。2008-09-09asp.net 驗(yàn)證字符串是否為純數(shù)字檢測(cè)函數(shù)
如何驗(yàn)證字符串是否為純數(shù)字2010-03-03.NET Core跨平臺(tái)串口通訊使用SerialPortStream基礎(chǔ)類庫(kù)問(wèn)題解決
這篇文章介紹了.NET Core跨平臺(tái)串口通訊使用SerialPortStream基礎(chǔ)類庫(kù)問(wèn)題解決,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01asp.net音頻轉(zhuǎn)換之.amr轉(zhuǎn).mp3(利用ffmpeg轉(zhuǎn)換法)
AMR轉(zhuǎn)MP3可實(shí)現(xiàn)將手機(jī)上的AMR錄音轉(zhuǎn)換成流行的MP3格式,以適用更廣泛的應(yīng)用。AMR的體積非常小,適用于存儲(chǔ)在手機(jī)中,當(dāng)我們想將在手機(jī)上的音頻上傳到網(wǎng)絡(luò),就需要將其轉(zhuǎn)換成MP3等流行的格式,本文就是介紹asp.net利用ffmpeg轉(zhuǎn)換法將.amr轉(zhuǎn).mp3的方法,下面來(lái)一起看看吧。2016-12-12最新評(píng)論