如果需要将删除函数更改为更新数据库值的函数,可按照以下步骤进行:
string updateQuery = "UPDATE 表名 SET 列名 = 新的值 WHERE 列名 = 某个值";
protected void btnUpdate_Click(object sender, EventArgs e) { string newValue = "新的值"; string oldValue = "某个值"; string connectionString = "连接字符串"; using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand(updateQuery, con); cmd.Parameters.AddWithValue("@newValue", newValue); cmd.Parameters.AddWithValue("@oldValue", oldValue); cmd.ExecuteNonQuery(); con.Close(); } }
protected void Page_Load(object sender, EventArgs e) { string connectionString = "连接字符串"; string selectQuery = "SELECT * FROM 表名"; using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); SqlDataAdapter da = new SqlDataAdapter(selectQuery, con); DataSet ds = new DataSet(); da.Fill(ds); gvData.DataSource = ds.Tables[0]; gvData.DataBind(); con.Close(); } }
这样,删除函数就被重新编写为更新数据库值的函数。