Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- using System.Web.Configuration;
- namespace WebApplication4
- {
- public partial class index : System.Web.UI.Page
- {
- SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["lista"].ConnectionString);
- protected void kiir()
- {
- string select ="Select * From posts";
- SqlCommand cmd = new SqlCommand(select,conn);
- SqlDataReader dr;
- try {
- conn.Open();
- dr=cmd.ExecuteReader();
- GridView1.DataSource=dr;
- GridView1.DataBind();
- dr.Close();
- }
- catch(Exception x){
- Label4.Text=x.ToString();
- }
- finally
- {
- conn.Close();
- };
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- kiir();
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- string insertstring = "INSERT INTO posts VALUES(@title,@desc)";
- SqlCommand insert = new SqlCommand(insertstring, conn);
- insert.Parameters.AddWithValue("@title", TextBox1.Text);
- insert.Parameters.AddWithValue("@desc", TextBox2.Text);
- try {
- conn.Open();
- if (insert.ExecuteNonQuery() < 0)
- Label4.Text = "Nem sikerult";
- }
- catch(Exception x){
- Label4.Text=x.ToString();
- }
- finally{conn.Close();
- kiir();
- }
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- string insertstring = "DELETE FROM posts Where title = @title";
- SqlCommand delete = new SqlCommand(insertstring, conn);
- delete.Parameters.AddWithValue("@title", TextBox1.Text);
- delete.Parameters.AddWithValue("@desc", TextBox2.Text);
- try {
- conn.Open();
- if (delete.ExecuteNonQuery() < 0)
- Label4.Text = "Nem sikerult";
- }
- catch(Exception x){
- Label4.Text=x.ToString();
- }
- finally{conn.Close();
- kiir();
- }
- }
- protected void Button3_Click(object sender, EventArgs e)
- {
- string insertstring = "UPDATE posts SET description = @desc WHERE title = @title";
- SqlCommand update = new SqlCommand(insertstring, conn);
- update.Parameters.AddWithValue("@title", TextBox1.Text);
- update.Parameters.AddWithValue("@desc", TextBox2.Text);
- try {
- conn.Open();
- if (update.ExecuteNonQuery() < 0)
- Label4.Text = "Nem sikerult";
- }
- catch(Exception x){
- Label4.Text=x.ToString();
- }
- finally{conn.Close();
- kiir();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement