怎么在网页上面实现C#添加数据到mysql
来源:百度知道 编辑:UC知道 时间:2024/07/04 22:52:47
我写的代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "";
sql = sql + "insert into test.user_table (UserID, Password, address, Email, Sex) values";
sql = sql + "('" + Name.Text ;
sql = sql + "','" + Password.Text;
sql = sql + "','" + adress.Text;
sql = sql + "', '" + email.Text;
sql = sql + "', '" + Sex.Text;
sql = sql +"')";
MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("localhost", "test", "root", "123456").AsString);
conn.Open();
MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
conn.Close()
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "";
sql = sql + "insert into test.user_table (UserID, Password, address, Email, Sex) values";
sql = sql + "('" + Name.Text ;
sql = sql + "','" + Password.Text;
sql = sql + "','" + adress.Text;
sql = sql + "', '" + email.Text;
sql = sql + "', '" + Sex.Text;
sql = sql +"')";
MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("localhost", "test", "root", "123456").AsString);
conn.Open();
MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
conn.Close()
改成这样就可以了
MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("localhost", "test", "root", "123456").AsString);
conn.Open();
string sql = "";
sql = sql + "insert into test.user_table (UserID, Password, address, Email, Sex) values";
sql = sql + "('" + Name.Text ;
sql = sql + "','" + Password.Text;
sql = sql + "','" + adress.Text;
sql = sql + "', '" + email.Text;
sql = sql + "', '" + Sex.Text;
sql = sql +"')";
MySQLCommand commn = new MySQLCommand(sql, conn);
commn.ExecuteNonQuery();
conn.Close();
去掉
MySQLDataAda