最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ASP.NET操作MySql数据库的教程
时间:2022-06-25 03:32:37 编辑:袖梨 来源:一聚教程网
一、把MySql.Data.dll放到BIN目录下。
二、这是aspx.cs的全部源码,修改参数直接运行即可!
usingMySql.Data.MySqlClient;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Data;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
publicpartialclassLogin : System.Web.UI.Page
{
publicstaticclassMySqlHelper
{
publicstaticintExecuteNonQuery(stringconnectionString, CommandType commandtype,stringcommandText)
{
returnExecuteNonQuery(connectionString, commandtype, commandText,null);
}
publicstaticintExecuteNonQuery(stringconnectionString, CommandType commandtype,stringcommandText,paramsMySqlParameter[] commandParameters)
{
if(string.IsNullOrEmpty(connectionString))
{
thrownewException("connectionString exception");
}
intresult = 0;
MySqlConnection con =null;
try
{
using(con =newMySqlConnection(connectionString))
{
con.Open();
MySqlCommand command =newMySqlCommand(commandText, con);
command.CommandType = commandtype;
result = command.ExecuteNonQuery();
}
returnresult;
}
catch(Exception ex)
{
throwex;
}
finally
{
if(con.State == ConnectionState.Open)
{
con.Close();
}
}
}
}
protectedvoidPage_Load(objectsender, EventArgs e)
{
stringconnectionString ="server=localhost;uid=root;pwd=;database=zentaopro;";
LogManage_SqlDate.WriteLog("connectionString=:"+ connectionString);
stringsql ="insert user(account) values('china2')";
MySqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, sql);
Console.Read();
}
}
|
相关文章
- 《夜族崛起》铁匠西里尔位置一览 05-17
- 《寓言之地》1.02更新内容一览 05-17
- 《辐射4》steam好评率介绍 05-17
- 《夜族崛起》技能强化珠宝掉落说明 05-17
- 《辐射4》主机控制台介绍 05-17
- 《星露谷物语》海草和绿藻获取方法 05-17