[英]how to delete selected row from datagridview
每當我運行它時,此異常就會出現“當nvarchar值'columnvalue'轉換為數據類型int時轉換失敗。” 知道為什么嗎? 這也是刪除行的永久方法嗎? 感謝您未來的建議!
Dim dataindex As Integer = Me.DataGridView1.CurrentRow.Index
Try
con = New SqlConnection
con.ConnectionString = Login.constring
Dim cmd As New SqlCommand("DELETE FROM tblmovies where movietitle = @a ", con)
cmd.Parameters.Add(New SqlParameter("@a", dataindex))
con.Open()
If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
cmd.ExecuteNonQuery()
con.Close()
Exit Sub
Else
con.Close()
Exit Sub
End If
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = DataGridView1.SelectedRows(0).Index
DataGridView1.Rows.RemoveAt(i)
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.