如上面的留言本,我想要在插入数据时先检查是否已经有了此人的留言或者Email,如果有,则弹出对话框,如果没有,则转到新的一页,但是为什么就是不成功呢?请求帮助,谢谢了先。
源代码如下:
OleDbConnection con=DB.createConnection();
con.Open();
OleDbCommand cmd=new OleDbCommand("select guestName,guestEmail from guestBook where guestName='"+this.txtName.Text+"' or guestEmail='"+this.txtEmail.Text+"'",con);
OleDbDataReader odr=cmd.ExecuteReader();
if(odr.Read())
{
Response.Write("<script>alert('很抱歉,你已经写下了留言,谢谢!'),</script>");
}
else
{
odr.Close();
string str="insert into guestBook(guestName,guestEmail,guestHomePage,guestTopic,guestSpeak,guestSpeakDate) values('"+this.txtName.Text+"','"+this.txtEmail.Text+"','"+this.txtHomePage.Text+"','"+this.txtTopic.Text+"','"+this.txtSpeak.Text+"','"+System.DateTime.Now+"')";
cmd.CommandText=str;
cmd.ExecuteNonQuery();
Response.Redirect("guestBookList.aspx");
}
if(!odr.IsClosed)
odr.Close();
cmd.Dispose();
con.Close();
con.Dispose();