views:

3

answers:

0

Hi friends my table name is nametable wherein i can store names like john bob

I am projecting the table values in the datagridview, and i am using delete button, for that i have written code below. But it deletes the data in the table and not showing in datagridview. How to solve it?

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex] == Delete ) { int i = dataGridView1.SelectedCells[0].RowIndex; string pickvalue = dataGridView1.Rows[i].Cells[0].Value.ToString();

            SqlConnection scon = new SqlConnection("Data Source=NAVEEN\\SQLEXPRESS;Initial Catalog=Userauth;User Id=naveen;Password=kumar");
            string strqry = "delete from nametable where name='" + pickvalue + "'";
            SqlCommand scmd = new SqlCommand(strqry, scon);

            scon.Open();
            scmd.ExecuteNonQuery();
            scon.Close();

            DataSet ds=new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(scmd);
            sda.Fill(ds,"nametable");

            dataGridView1.DataSource = ds.Tables["0"];
            dataGridView1.DataMember = "name";


        }
    }