.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> DataGrid >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Delete a seleted row from a DataGrid using c# windows application ...

Posted By:Syed Shakeer Hussain       Posted Date: February 16, 2009    Points: 10    Category: DataGrid    URL: http://www.dotnetspark.com  

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");
SqlCommand cmd = new SqlCommand("delect emp where empid=" + empid + "", conn);
MessageBox.Show("Row Deleted");



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend