一、把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();
}
}
|