I want to delete records from database in datagridview on window form app.
here is my code
System.Data.SqlClient.SqlCommandBuilder cb2;
cb2 = new System.Data.SqlClient.SqlCommandBuilder(da);
DataTable dt2 = ds.Tables["Employee"];
dt.PrimaryKey = new DataColumn[] { dt.Columns["EmpID"] };
dtDelete.Delete();
da.Update(ds, "Employee");
MessageBox.Show("Record Deleted");
int inc = 0;
int maxRow = 0;
maxRow = ds.Tables["tblImpi"].Rows.Count;
ds.Tables["tblImpi"].Rows[inc].Delete();
Update();
maxRow = ds.Tables["tblImpi"].Rows.Count;
inc--;
// NavigateRecords();
MessageBox.Show("Record Deleted");
This one works but only delete records from the first row only
Ramesh MaruthiPosted Oct 7, 2014, 10:10 AM
this links updates even in the database :
http://www.codeproject.com/Questions/454755/Csharp-Datagridview-update-and-delete
if you just want to delete on the front end you can do in this way
Munesh SharmaPosted Oct 7, 2014, 3:11 AM
kevinPosted Oct 7, 2014, 2:38 AM
Yes I'm selecting a row to delete but nothing is happening,I'm struggling to understand this part
of code,
private void dgv_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
(object sender, DataGridViewRowCancelEventArgs e) I'm not sure whether is a
button click event or where to look for it in the properties,because I tried to
a button,letter I removed that button click
Ramesh MaruthiPosted Oct 6, 2014, 11:46 AM
Are you selecting some rows or not from a gridview while deleting ?
kevinPosted Oct 6, 2014, 9:32 AM
H Ramesh I went to the link that you recommend I must check and I used the following code
and I still the an exception error
private void btnDel_Click(object sender, EventArgs e)
{
if (!e.Row.IsNewRow)
{
DialogResult res = MessageBox.Show("Are you sure you want to delete this row?", "Delete confirmation",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (res == DialogResult.No)
e.Cancel = true;
}
}
Ramesh MaruthiPosted Oct 2, 2014, 9:53 AM
Look at this link
http://www.dotnetcurry.com/showarticle.aspx?ID=132