private void button5_Click( object sender, EventArgs e) |
03 | if (MessageBox.Show( "确认删除该行吗?" , "删除" , MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes ) |
05 | SqlConnection conn = new SqlConnection(); |
06 | conn.ConnectionString = "Data Source=PC2012081514KSL\\MSSQL2008;Initial Catalog=db_book;Integrated Security=True" ; |
08 | int i = this .dataGridView1.SelectedRows.Count - 1; |
09 | Debug.WriteLine( "AA={0}" , i); |
10 | for ( int a = i; a >= 0; a--) |
12 | Debug.WriteLine( "a={0}" , a); |
13 | string sqlstring = "delete from tb_book where book_id='" +dataGridView1 .SelectedRows [a].Cells [0].Value .ToString ()+ "'" ; |
14 | SqlCommand cmd = new SqlCommand(sqlstring ,conn ); |
15 | cmd.ExecuteNonQuery(); |
19 | string sqlstring1= "select * from tb_book" ; |
20 | SqlCommand cmd1= new SqlCommand (sqlstring1 ,conn ); |
21 | SqlDataAdapter da= new SqlDataAdapter (cmd1); |
22 | cmd1 .ExecuteNonQuery (); |
23 | DataSet ds= new DataSet (); |
25 | dataGridView1 .DataSource =ds .Tables [0]; |
27 | MessageBox .Show ( "删除成功!" ); |
转载于:https://blog.51cto.com/qyweiyy/1147453