我有一个示例网站,您可以在其中输入您的电子邮件地址,并将其插入 MS SQL 数据库。在下一页上,GridView 显示来自数据库的列表。现在我需要添加一个删除地址的函数,但它必须验证该地址当前是否为
public partial class Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = GetLastWriteTime(Request.PhysicalPath).ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
string data = DateTime.Now.ToLongDateString() + "," + DateTime.Now.ToLongTimeString() + ": ";
SqlDataSource1.InsertCommand = "INSERT INTO ListaAdresow (Email) Values('" + TextBox1.Text + "')";
try
{
SqlDataSource1.Insert();
Label2.Text += data + "added into database: " + TextBox1.Text + "<br/>";
TextBox1.Text = "";
}
catch (Exception ex)
{
Label2.Text += data + ex.Message;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string data = DateTime.Now.ToLongDateString() + "," + DateTime.Now.ToLongTimeString() + ": ";
SqlDataSource1.DeleteCommand = "DELETE FROM ListaAdresow WHERE Email='" + TextBox1.Text + "'";
SqlDataSource1.SelectCommand = "SELECT FROM [ListaAdresow] WHERE Email=" + TextBox1.Text;
try
{
SqlDataSource1.Delete();
Label2.Text += data + "removed from database: " + TextBox1.Text + "<br/>";
TextBox1.Text = "";
}
catch (Exception ex)
{
Label2.Text += data + ex.Message;
}
}
}