using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using System.Web.Configuration; using System.Collections; using System.Collections.Generic; /// <summary> /// Summary description for Class1 /// </summary> namespace bll { public class Class1 { public Class1() { // // TODO: Add constructor logic here // } // private static readonly _connection; private string _title; private int _id; public string Movie { get{return _title;} set{ _title = value; } } public int id { get{ if(_id < 0 ) throw new Exception("Id should be greater than 0"); return _id;} set{ _id=value; } } public List<class1> getall() { List<class1> results = new List<class1>(); SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Practice1\App_Data\Database.mdf;Integrated Security=True;User Instance=True"); con.StatisticsEnabled = true; SqlCommand cmd = new SqlCommand("sel",con); cmd.CommandType = CommandType.StoredProcedure; using(con) { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while(reader.Read()) { Class1 c = new Class1(); c.id = (int)reader["Id"]; c.Movie= (string)reader["Movie"]; results.Add(c); } return results; } } public void delete(int i) { SqlConnection sc = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Practice1\App_Data\Database.mdf;Integrated Security=True;User Instance=True"); SqlCommand cmd = new SqlCommand("delete Movies where Id=@Id"); cmd.Parameters.AddWithValue("@Id",i); using(sc) { sc.Open(); cmd.ExecuteNonQuery(); } } public void update(int i, string mov) { SqlConnection sc = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Practice1\App_Data\Database.mdf;Integrated Security=True;User Instance=True"); SqlCommand cmd = new SqlCommand("update Movies set Movie=@Movie where Id=@Id",sc); cmd.Parameters.AddWithValue("@Movie",mov); cmd.Parameters.AddWithValue("@Id",i); using (sc) { sc.Open(); cmd.ExecuteNonQuery(); } } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" DataSourceID="obj" ID="gv" runat="server" /> <asp:ObjectDataSource ID="obj" TypeName="bll.Class1" SelectMethod="getall" UpdateMethod="update" DeleteMethod="delete" runat="server" /> </div> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)