void bindComment() { try { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("select * from Comments where BlogId=@id", con); cmd.Parameters.AddWithValue("@id", Request.QueryString["Id"]); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); if (ds.Tables[0].Rows.Count == 0) { GridViewcomment.Visible = false; LabelNoComment.Visible = true; } else { GridViewcomment.Visible = true; LabelNoComment.Visible = false; GridViewcomment.DataSource = ds; GridViewcomment.DataBind(); } } catch (Exception) { throw; } finally { con.Close(); } }
void bindComment() { try { con.Open(); MySqlCommand cmd = new MySqlCommand("select * from coment where blog_id=@id", con); cmd.Parameters.AddWithValue("@id", Request.QueryString["a_id"]); MySqlDataAdapter adp = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); if (ds.Tables[0].Rows.Count == 0) { GridViewcomment.Visible = false; LabelNoComment.Visible = true; } else { GridViewcomment.Visible = true; LabelNoComment.Visible = false; GridViewcomment.DataSource = ds; GridViewcomment.DataBind(); } } catch (Exception) { con.Close(); } finally { } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString.Get("Tip").ToString() == "Comms") { GridViewcomment.Visible = true; try { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("select * from Comentarii where Nume = @nume", con); cmd.Parameters.AddWithValue("@nume", Request.QueryString["NumeUser"]); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); if (ds.Tables[0].Rows.Count == 0) { GridViewcomment.Visible = false; LabelNoComment.Visible = true; } else { GridViewcomment.Visible = true; LabelNoComment.Visible = false; GridViewcomment.DataSource = ds; GridViewcomment.DataBind(); } } catch (Exception) { throw; } } if (Request.QueryString.Get("Tip").ToString() == "Categ") { GridView1.Visible = true; try { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("select * from BlogPost where Categorie = @categ order by DataPost desc ", con); cmd.Parameters.AddWithValue("@categ", Request.QueryString["NumeCateg"]); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); cmd.Dispose(); } catch (Exception k) { Response.Write(k.Message); } } if (Request.QueryString.Get("Tip").ToString() == "Normal") { GridView1.Visible = true; try { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("select * from BlogPost where Titlu like '%" + Request.QueryString["Cautare"].ToString() + "%' or Continut like '%" + Request.QueryString["Cautare"] + "%'", con); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); cmd.Dispose(); } catch (Exception k) { Response.Write(k.Message); } } if (Request.QueryString.Get("Tip").ToString() == "Posts") { GridView1.Visible = true; try { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("select * from BlogPost where Autor = @numeautor order by DataPost desc ", con); cmd.Parameters.AddWithValue("@numeautor", Request.QueryString["NumeAutor"]); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); cmd.Dispose(); } catch (Exception k) { Response.Write(k.Message); } } con.Close(); }