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("删除完成!")

解决方案 »

  1.   

     Dim sql As String = "delete from 用户表 where ID=" & DataGridView1.CurrentRow.Cells(0).Value.ToString & ""DataGridView1默认选择第一行 你如果DataGridView1没有手动选择哪一行  它就默认选择第一行 你删除肯定就是第一行了
      

  2.   

    你上面怎么写了两种删除?你使用了bindingSource控件了吗?用那个比较好管理,MyBindSource.RemoveAt(MyGridView.CurrentRow.Index)就可以删除当前行。
      

  3.   

    用户表TableAdapter.Update(参数化绘图管理系统DataSet2.Tables("用户表"))
     如果不加这句就在数据库中就删不掉记录
      

  4.   

    我使用了DataGridView1.CellClick事件:
            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()& ""
    还是不行?该如何办
      

  5.   

    鼠标点选行啊,点到哪行哪行就会成为当前行.如果使用bindingSource可以轻松管理。
      

  6.   

    Dim sql As String = "delete from 用户表 where ID=" & DataGridView1.CurrentRow.Cells(0).Value  
      

  7.   

    完美解决vb.net删除DataGridView中光标所在的记录
      

  8.   

    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()   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("删除完成!")
      

  9.   


    楼主 请教下怎么删除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
    我这代码都删除第一行
      

  10.   


    请教下 我的帖子 http://topic.csdn.net/u/20120503/13/1e8ce256-aad3-471a-abbe-33a8a0fc3de9.html