Introduction
This Code for Insert Update and Delete in Generic List in ASP.Net with C#
Using This Code
Insert Update and Delete in List
This Code for Insert Update and Delete in Generic List in ASP.Net with C#
Using This Code
Insert Update and Delete in List
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace GenericList { public partial class frmContact : Form { List contacts; public frmContact() { InitializeComponent(); } # region Insert Operationprivate void btnInsert_Click(object sender, EventArgs e){ Customer cnt = new Customer(); cnt.Name = txtName.Text.Trim(); cnt.Mobile = txtMobile.Text.Trim(); contacts.Add(cnt); CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts]; cm.Refresh(); dgcontacts.DataSource = contacts; } # endregion #region Update Operationprivate void btnUpdate_Click(object sender, EventArgs e){ List select = contacts.FindAll(new Predicate(HasName)); if (select.Count > 0) // record found { foreach (Customer cnt in select) { cnt.Name = txtName.Text.Trim(); cnt.Mobile = txtMobile.Text.Trim(); } CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts]; cm.Refresh(); dgcontacts.DataSource = contacts; } else { MessageBox.Show("No records found"); } } # endregion //This function will check for the person name bool HasName(Customer c) { return (c.Name == txtName.Text); } # region Delete Operationprivate void btnDelete_Click(object sender, EventArgs e){ List select = contacts.FindAll(new Predicate(HasName)); if (select.Count > 0) // record found { foreach (Customer cnt in select) { contacts.Remove(cnt); } CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts]; cm.Refresh(); dgcontacts.DataSource = contacts; } else { MessageBox.Show("No records found"); } } # endregion private void frmContact_Load(object sender, EventArgs e) { contacts = new List(); } } //Customer Classpublic class Customer{private string _Name;private string _Mobile;public string Name{get { return _Name; }set { _Name = value; }}public string Mobile{get { return _Mobile; }set { _Mobile = value; }}}} |
sql insert , Update , delete using c#
with code , easy explanation and demo app
http://geeksprogrammings.blogspot.com/2014/05/sql-insert-update-delete-using-c.html