Subscribe For Free Updates!

We'll not spam mate! We promise.

Sep 29, 2011

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

Views:

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");

    }


Plese Feel Free to Socializer This Post
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment

Become a Fan

visual studio learn