First, put the MySql.Data.dll in the bin directory.
Second, this is the aspx.cs of all the source code, modify the parameters to run directly!
UsingMySql.Data.MySqlClient;
UsingSystem.Collections.Generic;
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");
Mysqlconnection con =null;
using (Con =newmysqlconnection (connectionString))
Mysqlcommand command =newmysqlcommand (CommandText, con);
Command.commandtype = CommandType;
result = command. ExecuteNonQuery ();
if (Con. state = = ConnectionState.Open)
Protectedvoidpage_load (Objectsender, EventArgs e)
stringconnectionstring = "server=localhost;uid=root;pwd=;d atabase=zentaopro;";
Logmanage_sqldate.writelog ("connectionstring=:" + connectionString);
Stringsql = "Insert User (account) VALUES (' China2 ')";
Mysqlhelper.executenonquery (connectionString, CommandType.Text, SQL);
|