在formview插入新记录时添加当前时间并检验记录是否重复
protected void FormView1_ItemInserting(Object sender, FormViewInsertEventArgs e)
{
TextBox signdatefindbox = (TextBox)FormView1.FindControl("signdate");
if (signdatefindbox != null)
{
signdatefindbox.Text = DateTime.Now.ToString();
}
SqlDataSource1.InsertParameters["signdate1"].DefaultValue = signdatefindbox.Text;
TextBox emailcheck = (TextBox)FormView1.FindControl("email");
OleDbConnection conn;
OleDbCommand cmd;
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["DbPath"]));
cmd = new OleDbCommand("select * from userinfo where email='"+emailcheck .Text+"'", conn);
conn.Open();
OleDbDataReader rows=cmd.ExecuteReader();
bool checkrows = rows.HasRows;
if (checkrows)
{
Label1.Text = "<br>您的电子邮件: " + emailcheck.Text + " <font color=blue>以前已经登记过了</font>";
e.Cancel = true;
}
}

浙公网安备 33010602011771号