Hi I' developing a windows orm application in c# usin vs 2010. I use sql server 2008 R2 as the db.
I have a data gridview in a form and I have provided a delete button in the form to delete the rows in the data grid view.
once I build and run it the row get deleted but after I close the form and reopen it , the row is still there... I don't know how to solve this please help thanks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
namespace HematologyLab
{
public partial class ViewPatient : Form
{
public ViewPatient()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Hide();
this.Close();
}
private void patientBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.patientBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.hematologyDataSet);
}
private void Form8_Load(object sender, EventArgs e)
{
string type = Common.type.ToString();
if (type == "user2")
{
btnDelete.Visible = false;
}
this.patientTableAdapter.Fill(this.hematologyDataSet.Patient);
this.patientDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
this.patientDataGridView.MultiSelect = false;
this.patientDataGridView.DataSource = patientBindingSource;
}
private void patientDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
btnDelete.Enabled = true;
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (this.patientDataGridView.SelectedRows.Count > 0)
{
DialogResult confirm = MessageBox.Show("Are you sure you want to delete the selected row(s)?", "Confirm Delete", MessageBoxButtons.OKCancel);
if (confirm == DialogResult.OK)
{
// I want to make the user selected rows deleted from the datagridview and from the database
patientBindingSource.RemoveAt(this.patientDataGridView.SelectedRows[0].Index);
}
if (confirm == DialogResult.Cancel)
{
patientDataGridView.Refresh();
}
}
else
{
MessageBox.Show("Please select a row to delete", "Delete");
}
}
private void btnColse_Click(object sender, EventArgs e)
{
this.Hide();
this.Close();
}
}
}