private void btnDelete_Click(object sender, EventArgs e) { try { ds.Tables[0].Rows[inc].Delete(); objConnect.UpdateDatabase(ds); this.ds.Reset(); MaxRows = ds.Tables[0].Rows.Count; inc = inc-1; NavigateRecords(ds); MessageBox.Show("Records Deleted"); } catch (Exception err) { MessageBox.Show(err.Message); } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace testNavData { public partial class Form1 : Form { public Form1() { InitializeComponent(); } DatabaseConnection objConnect; string conString; DataSet ds; DataRow dRow; int MaxRows; int inc = 0; private void Form1_Load(object sender, EventArgs e) { DataSet ds1=new DataSet(); try { objConnect = new DatabaseConnection(); conString = Properties.Settings.Default.EmployeesConnectionString; objConnect.connection_string = conString; objConnect.Sql = Properties.Settings.Default.SQL;; //MessageBox.Show(get{return objConnect.Sql}); ds = objConnect.GetConnection; MaxRows = ds.Tables[0].Rows.Count; NavigateRecords(ds); } catch (Exception err) { MessageBox.Show(err.Message); } } private void NavigateRecords(DataSet ds) { dRow = ds.Tables[0].Rows[inc]; txtFirstName.Text = dRow.ItemArray.GetValue(1).ToString(); txtSurname.Text = dRow.ItemArray.GetValue(2).ToString(); txtJobTitle.Text = dRow.ItemArray.GetValue(3).ToString(); txtDepartment.Text = dRow.ItemArray.GetValue(4).ToString(); } private void btnAddNew_Click(object sender, EventArgs e) { txtFirstName.Clear(); txtSurname.Clear(); txtJobTitle.Clear(); txtDepartment.Clear(); btnAddNew.Enabled = false; btnSave.Enabled = true; btnCancel.Enabled = true; } private void btnCancel_Click(object sender, EventArgs e) { NavigateRecords(ds); btnCancel.Enabled = false; btnAddNew.Enabled = true; btnSave.Enabled = false; } private void btnSave_Click(object sender, EventArgs e) { DataRow row = ds.Tables[0].NewRow(); row[1] = txtFirstName .Text; row[2] = txtSurname.Text; row[3] = txtJobTitle.Text; row[4] = txtDepartment.Text; ds.Tables[0].Rows.Add(row); try { objConnect.UpdateDatabase(ds); MaxRows = MaxRows + 1; inc = MaxRows - 1; this.ds.Tables[0].Clear(); MessageBox.Show("Database is Updated"); } catch(Exception err) { MessageBox.Show(err.Message); } btnCancel.Enabled = false; btnSave.Enabled = false; btnAddNew.Enabled = true; } public string Sql { get; set; } private void btnNext_Click(object sender, EventArgs e) { if (inc != (MaxRows-1)) { inc= inc+1; NavigateRecords(ds); } else { if (inc != (MaxRows - 1)) { inc = (MaxRows-1); NavigateRecords(ds); } } } private void btnPrevious_Click(object sender, EventArgs e) { if (inc > 0) { inc= inc-1; NavigateRecords(ds); } else { if (inc != 0) { inc = 0; NavigateRecords(ds); } } } private void btnLast_Click(object sender, EventArgs e) { if (inc != M
ds
ds1
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)