I think you are fixed the condition in your query :
"update student set name='ali' where id=2";
"delete from student where id=1";
you should use something like that :
if you need to update one recorde the selected one use :
int k = dataGridView1.CurrentRow.Index;
"update student set name='"+dataGridView1.Rows[k].Cells["the cell name"].Value.ToString()+"' where id="+dataGridView1.Rows[k].Cells["the number of the cell or the cell id name"].Value
if you need to update them all you should use loop
for(int i =0;i<datagridview1.rows.count;i++)>
and the work here