conn = New SqlClient.SqlConnection("user id=sa;password=huangjing;initial catalog=学生成绩信息管理系统;data source=(local)")
conn.Open()
Dim sql As String = "delete from 用户表 where ID=" & DataGridView1.CurrentRow.Cells(0).Value.ToString & ""
Dim comm As SqlClient.SqlCommand = New SqlClient.SqlCommand(Sql, conn)
comm.ExecuteNonQuery() 参数化绘图管理系统DataSet2.Tables("用户表").Rows(Me.BindingContext(参数化绘图管理系统DataSet2, "用户表").Position).Delete()
用户表TableAdapter.Update(参数化绘图管理系统DataSet2.Tables("用户表"))
参数化绘图管理系统DataSet2.Tables("用户表").AcceptChanges(
conn.Close()
MessageBox.Show("删除完成!")
conn.Open()
Dim sql As String = "delete from 用户表 where ID=" & DataGridView1.CurrentRow.Cells(0).Value.ToString & ""
Dim comm As SqlClient.SqlCommand = New SqlClient.SqlCommand(Sql, conn)
comm.ExecuteNonQuery() 参数化绘图管理系统DataSet2.Tables("用户表").Rows(Me.BindingContext(参数化绘图管理系统DataSet2, "用户表").Position).Delete()
用户表TableAdapter.Update(参数化绘图管理系统DataSet2.Tables("用户表"))
参数化绘图管理系统DataSet2.Tables("用户表").AcceptChanges(
conn.Close()
MessageBox.Show("删除完成!")
如果不加这句就在数据库中就删不掉记录
If e.RowIndex < DataGridView1.Rows.Count - 1 Then
TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString
End If
然后修改 Dim sql As String = "delete from 用户表 where ID=" & TextBox1.Text.ToString()& ""
还是不行?该如何办
conn.Open()
Dim sql As String = "delete from 用户表 where ID=" & DataGridView1.CurrentRow.Cells(0).Value.ToString & ""
Dim comm As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql, conn)
comm.ExecuteNonQuery() Dim mybind As BindingManagerBase
mybind = Me.BindingContext(参数化绘图管理系统DataSet2, "用户表")
mybind.Position = DataGridView1.CurrentCell.RowIndex '这个是关键,指针变为选定删除行的索引 参数化绘图管理系统DataSet2.Tables("用户表").Rows(mybind.Position).Delete() '物理删除
用户表TableAdapter.Update(参数化绘图管理系统DataSet2.Tables("用户表")) '更新
参数化绘图管理系统DataSet2.Tables("用户表").AcceptChanges() '内存中删除
conn.Close()
MessageBox.Show("删除完成!")
楼主 请教下怎么删除datagrid中选中行的数据呢,简单点说下。If Adodc1.Recordset.EOF = False Then
K = MsgBox("真的要删除当前记录吗?", vbYesNo + vbQuestion, "警告")
If K = 6 Then '点击“是”
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Adodc1.Refresh
DataGrid1.Refresh
End If
Else
MsgBox "系统提示:所有记录已经删除。"
End If
我这代码都删除第一行
请教下 我的帖子 http://topic.csdn.net/u/20120503/13/1e8ce256-aad3-471a-abbe-33a8a0fc3de9.html