[求助]在datagridview中删除问题
我想请问下各位,在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中的数据,不能同时删除到数据库,请问要删除到数据库应该怎么写呢?