日期:2014-05-18 浏览次数:20815 次
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = "server=(local);database=Meet;Integrated Security=SSPI";// 创建命令(SqlCommand)对象(cmd) SqlCommand cmd = new SqlCommand(); cmd.Connection = con; // 指示命令发给哪个数据库 cmd.CommandType = CommandType.Text; // 指示是什么类型的命令 cmd.CommandText = "select * from [care] where NAME_user = '" + this.Label3.Text.ToString() + " ' and TITLE_meet = '" + this.titlelabel.Text.ToString() + " '"; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); try { if (reader.Read()) { reader.Close(); Response.Write(" <script>alert(' 您已关注过此会议 ') </script>"); } else { reader.Close(); cmd.CommandText = "update [meet] set HOT_meet = HOT_meet + 1 where TITLE_meet='" + this.titlelabel.Text.ToString() + "'"; SqlCommand cmd2 = new SqlCommand(); cmd2.Connection = con; cmd2.CommandType = CommandType.Text; cmd2.CommandText = "insert into [care](NAME_user,TITLE_meet) values(@nameuser,@meettitle)"; cmd2.Parameters.Add("@nameuser",SqlDbType.VarChar,50); cmd2.Parameters["@nameuser"].Value = Label3.Text; cmd2.Parameters.Add("@meettitle", SqlDbType.VarChar,100); cmd2.Parameters["@meettitle"].Value = titlelabel.Text; int i = cmd.ExecuteNonQuery(); Response.Write("<script>alert('您已经关注成功');</script>"); hotlabel.Text = Convert.ToString(Convert.ToInt32(hotlabel.Text) + 1); } con.Close(); } catch { } }