注册 登录
编程论坛 VB.NET论坛

[求助]在datagridview中删除问题

hyuecai 发布于 2008-04-04 11:25, 1412 次点击
我想请问下各位,在datagridview中要怎么删除数据呀就是也要把数据库的数据也删除,以下是我写的代码:
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim row As Integer = dgv.CurrentRow.Index


        If row >= 0 And row < dgv.RowCount Then


            If MessageBox.Show("确定要删除?", "删除确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.OK Then
                Dim sql As String = "delete from login where username=''"
                Dim sqlcmd As New SqlClient.SqlCommand
                sqlcmd.Connection = sqlconn
                = sql
                Try
                    sqlconn.Open()
                    sqlcmd.ExecuteNonQuery()
                    MessageBox.Show("删除成功")

                Catch ex As Exception
                    MessageBox.Show("删除失败")

                    writeerr(ex)
                Finally
                    sqlconn.Close()


                End Try

            End If
        End If

    End Sub
它提示删除成功,但是数据没有删除到呀,数据库中也没有删除到,请各位帮帮忙呀,有一种是用remove的,但是只能删除datagridview中的数据,不能同时删除到数据库,请问要删除到数据库应该怎么写呢?
2 回复
#2
qlong07282008-04-05 08:14
Dim sql As String = "delete from login where username=''"
Dim sqlcmd As New SqlClient.SqlCommand(sql, sqlconn)
sqlcmd.ExecuteNonQuery()
#3
hyuecai2008-04-05 21:05
谢谢版主的回复,但我试了,不行呀,在查询分析器里说删除影响是O行,是什么意思呀,麻烦知道的说下呀~~
1