ASP.NET中密码修改

来源:百度知道 编辑:UC知道 时间:2024/06/08 16:45:04
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string sqlcon = "Data Source=(local);Initial Catalog=客户关系管理;Integrated Security=True";
SqlConnection myConnection = new SqlConnection(sqlcon);
SqlCommand com = new SqlCommand("update 管理员信息 set 密码 = '" + TextBox3.Text + "' where 员工编号= '" + TextBox1.Text + "'");
myConnection.Open();
com.ExecuteNonQuery();

myConnection.Close();

Label6.Text = "更新成功";
}
catch
{

Label6.Text = "重新输入";
}

我想知道哪里不对,高人指教

protected void Button1_Click(object sender, EventArgs e)
{
try
{
string sqlcon = "Data Source=(local);Initial Catalog=客户关系管理;Integrated Security=True";
SqlConnection myConnection = new SqlConnection(sqlcon);
myConnection.Open();
SqlCommand com = new SqlCommand("update 管理员信息 set 密码 = '" + TextBox3.Text + "' where 员工编号= '" + TextBox1.Text + "'");
com.Connection = myConnection;
com.ExecuteNonQuery();
Label6.Text = "更新成功";
}
catch
{
Label6.Text = "重新输入";
}
finally
{
myConnection.Close();
}
}

这样就行了 ,建议把打开连接写成单独的方法,需要连接的时候,传入连接参数就行了,友情提示:别忘了调用完一定关闭,要不IIS某天就会出现连接池满了

SqlCommand com = new SqlCommand("update 管理员信息