编辑某条符合要求的记录并处理下一条

来源:互联网 发布:iphone照片导入mac 编辑:程序博客网 时间:2024/05/17 04:45

void Page_Load(Object Src, EventArgs E)
{
string SQL = "SELECT top 1 * FROM password WHERE bhh IS NULL";//找到 bhh为空的第一个记录
SqlConnection Conn;
Conn = new SqlConnection("连接数据库");
Conn.Open();
//Response.Write(SQL);
SqlCommand Comm=new SqlCommand(SQL,Conn);

SqlDataReader dr=Comm.ExecuteReader();
 if (dr.Read())
  {Label1.Text=dr["xxx"].ToString();
   Label2.Text=dr["yyy"].ToString();
   Label3.Text=dr["zzz"].ToString();
   Conn.Close();
  }
 else
  {
  Conn.Close();
  Response.Redirect("bhend.ASPX?");//如果没有符合要求的记录则跳出
  }

}

void ONButton1Click(Object sender, EventArgs e) //单击保存并处理下一条按钮
 {
string user = Label1.Text;
SqlConnection Conn1;
Conn1 = new SqlConnection("连接数据库");
string SQL1= "UPDATE Password SET bhh = ";
SQL1 = SQL1 + "'"+ TextBox1.Text +"'where name ='"+user+"'";
SqlCommand Comm1=new SqlCommand(SQL1,Conn1);
Conn1.Open();
Comm1.ExecuteNonQuery();
Conn1.Close();
TextBox1.Text="";
Response.Redirect("bhgl.ASPX?");//刷新页面
}