using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Configuration; using System.Data.OleDb; namespace DatabaseDemoWithAccessVC { public partial class ManageEmployeesForm : Form { public ManageEmployeesForm() { InitializeComponent(); } private DataTable dtEmployees = new DataTable(); private void ManageEmployeesForm_Load(object sender, EventArgs e) { LoadDataIntoDataGridView(); } private void LoadDataIntoDataGridView() { EmployeesListDataGridView.DataSource = GetEmployeesList(); } private DataTable GetEmployeesList() { //DataTable dtEmployees = new DataTable(); dtEmployees.Rows.Clear(); string connString = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString; using (OleDbConnection con = new OleDbConnection(connString)) { using (OleDbCommand cmd = new OleDbCommand("SELECT * FROM Employees", con)) { con.Open(); OleDbDataReader reader = cmd.ExecuteReader(); dtEmployees.Load(reader); } } return dtEmployees; } private void closeToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void resetFormToolStripMenuItem_Click(object sender, EventArgs e) { NameTextBox.Clear(); EmailTextBox.Clear(); MobileTextBox.Clear(); PhoneTextBox.Clear(); } private void NameTextBox_TextChanged(object sender, EventArgs e) { //DataView dvEmployees = dtEmployees.DefaultView; //dvEmployees.RowFilter = "Name LIKE '%" + NameTextBox.Text + "%'"; FilterDataByColumn("Name", NameTextBox); } private void EmailTextBox_TextChanged(object sender, EventArgs e) { //DataView dvEmployees = dtEmployees.DefaultView; //dvEmployees.RowFilter = "Email LIKE '%" + EmailTextBox.Text + "%'"; FilterDataByColumn("Email", EmailTextBox); } private void FilterDataByColumn(string columnName, TextBox txtBox) { DataView dvEmployees = dtEmployees.DefaultView; dvEmployees.RowFilter = columnName + " LIKE '%" + txtBox.Text + "%'"; } private void MobileTextBox_TextChanged(object sender, EventArgs e) { FilterDataByColumn("Mobile", MobileTextBox); } private void PhoneTextBox_TextChanged(object sender, EventArgs e) { FilterDataByColumn("Phone", PhoneTextBox); } private void addNewEmployeeToolStripMenuItem_Click(object sender, EventArgs e) { EmployeeInfoForm eif = new EmployeeInfoForm(); eif.ShowDialog(); LoadDataIntoDataGridView(); } } }
Sunday, October 21, 2012
C# Access Database Tutorials In Urdu (Code) - Manage Employee Screen
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment