publicvoidbtn_register_Click(objectsender,EventArgse){using(SqlConnectionconnection=newSqlConnection("DataSource=127.0.0.1;InitialCatalog=test;IntegratedSecurity=True;"))...
public void btn_register_Click(object sender, EventArgs e)
{
using(SqlConnection connection = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=test;Integrated Security=True;"))//初始化到数据库的连接
{
try
{
connection.Open();//打开此数据库连接
SqlCommand sqlText = new SqlCommand("insert into zhuce values (@nm,@rn,@pw)", connection);//建立数据库命令对象
//添加数据库命令参数 Response.Write("");
// MessageBox.Show(this, "注册失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
//Response.Write("");
sqlText.Parameters[0].Value = txt_username.Text;
sqlText.Parameters[1].Value = txt_userregname.Text;
sqlText.Parameters[2].Value = txt_password.Text;
if (sqlText.ExecuteNonQuery())
Response.Write("");
else
Response.Write("");
}
catch (SqlException exception)
{
Response.Write("");
}
finally
{
connection.Close();
}
}
}
展开