編輯某條符合要求的記錄並處理下一條

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?");//刷新頁面
}
 
 

發佈了16 篇原創文章 · 獲贊 1 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章