using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using MySql.Data.MySqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string mySqlConnectionString="Database=newdb;Data Source=localhost;User Id=root;Password="; using (MySqlConnection myCon = new MySqlConnection(mySqlConnectionString)) { using (MySqlCommand cmd = new MySqlCommand("INSERT INTO Test(uid,regdate,remark) values(@uid,curdate(),@remark)", myCon)) { cmd.Parameters.Add(new MySqlParameter("@uid",this.TextBox1.Text.Trim())); cmd.Parameters.Add(new MySqlParameter("@remark",this.TextBox2.Text.Trim())); myCon.Open(); if(cmd.ExecuteNonQuery()==1) { Response.Write("<mce:script type="text/javascript"><!-- alert('成功添加了一条记录') // --></mce:script>"); } else { Response.Write("<mce:script type="text/javascript"><!-- alert('添加失败!!!') // --></mce:script>"); } } } } }