Place a DataGrid on the form and populate it, now double click the dataGrid and use the below code.
private void DataGridvie_selected(Object sender, EventArgs e)
{
DataSet da = new DataSet();
//when you select a row that index will storing in i variable
int j = datagrid1.selectedIndex;
int empidval = ds.Tables["emp"].Rows[j][0].ToString();
//above what you had selected that row value exa:empid has 101 is stored in empidval vairable
//write the delete query
SqlConnection conn = new Sqlconnection("conn string");
conn.Open();
SqlCommand cmd = new SqlCommand("delect emp where empid=" + empid + "", conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Row Deleted");
}CODE]
Thanks
Hi,
i want to Delete a seleted row from a DataGrid using c# windows application.for that i have two tables tbl_report1,tbl_report2
tbl_report1 columns:invoiceno(FK),particulars,quantity,perprice,amount,compname,invoicedate,ondate,orderno,invoiceid.
tbl_report2 columns:compname,compaddress,invoiceno(PK),orderno,ondate,invoicedate,amountstatus,netamount,netvat,tamount
from above two tables i have to design a query for delete and update.based on invoiceno.please do the needful.