ASP.NET操作MySql數(shù)據(jù)庫的實(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ù)庫的實(shí)例代碼講解,希望對(duì)大家有所幫助,如果大家有任何疑問請(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-09
Linux上使用Docker部署ASP.NET?Core應(yīng)用程序
這篇文章介紹了使用Docker部署ASP.NET?Core應(yīng)用程序的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03
淺談.NET中加密和解密的實(shí)現(xiàn)方法分享
這篇文章介紹了.NET中加密和解密的實(shí)現(xiàn)方法,有需要的朋友可以參考一下2013-11-11
asp.net 驗(yàn)證字符串是否為純數(shù)字檢測函數(shù)
如何驗(yàn)證字符串是否為純數(shù)字2010-03-03
.NET Core跨平臺(tái)串口通訊使用SerialPortStream基礎(chǔ)類庫問題解決
這篇文章介紹了.NET Core跨平臺(tái)串口通訊使用SerialPortStream基礎(chǔ)類庫問題解決,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01
asp.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的方法,下面來一起看看吧。2016-12-12

