Advertisement
Milotronik

Linq 12 ABM

Jun 7th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. public partial class _12 : System.Web.UI.Page
  9. {
  10.     protected void Page_Load(object sender, EventArgs e)
  11.     {
  12.         RellenarGridView();
  13.     }
  14.  
  15.     protected void RellenarGridView()
  16.     {
  17.         DataClassesDataContext db = new DataClassesDataContext();
  18.  
  19.         var qry = from ship in db.Shippers
  20.                   select ship;
  21.  
  22.         GridView1.DataSource = qry;
  23.         GridView1.DataBind();
  24.     }
  25.  
  26.     protected void Actualizar(int id)
  27.     {
  28.         DataClassesDataContext db = new DataClassesDataContext();
  29.         var qry = (from ship in db.Shippers
  30.                   where ship.ShipperID == id
  31.                   select ship).Single();
  32.  
  33.         qry.CompanyName = txtBxCompanyName.Text;
  34.         qry.Phone = txtBxPhone.Text;
  35.  
  36.         db.SubmitChanges();
  37.  
  38.     }
  39.  
  40.     protected void Insertar()
  41.     {
  42.         DataClassesDataContext db = new DataClassesDataContext();
  43.  
  44.         Shippers ship = new Shippers();
  45.  
  46.         ship.CompanyName = txtBxCompanyName.Text;
  47.         ship.Phone = txtBxPhone.Text;
  48.  
  49.         db.Shippers.InsertOnSubmit(ship);
  50.         db.SubmitChanges();
  51.  
  52.    
  53.     }
  54.  
  55.     protected void Eliminar(int id)
  56.     {
  57.         DataClassesDataContext db = new DataClassesDataContext();
  58.         var qry = (from ship in db.Shippers
  59.                    where ship.ShipperID == id
  60.                    select ship).Single();
  61.  
  62.         db.Shippers.DeleteOnSubmit(qry);
  63.         db.SubmitChanges();
  64.  
  65.     }
  66.  
  67.     protected void Button1_Click1(object sender, EventArgs e)
  68.     {
  69.         Actualizar(Convert.ToInt32(txtId.Text));
  70.         RellenarGridView();
  71.     }
  72.     protected void Button2_Click(object sender, EventArgs e)
  73.     {
  74.         Insertar();
  75.         RellenarGridView();
  76.     }
  77.     protected void Button3_Click(object sender, EventArgs e)
  78.     {
  79.         Eliminar(Convert.ToInt32(txtId.Text));
  80.         RellenarGridView();
  81.     }
  82.  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement