我一直在研究可以从sql数据库中删除用户的表。我几乎改变了所有内容,无法正常工作。
Private Sub ButtonDelete_Click(sender As Object, e As EventArgs) Handles ButtonDelete.Click
Try
If MessageBox.Show("Do you really want to delete this User?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
connection = New SqlConnection(My.Settings.ConString)
Dim command As New SqlCommand("Delete from Operator where User = @User")
command.Parameters.Add("@User", SqlDbType.NVarChar).Value = DataGridView1.SelectedRows(0).Cells(0).FormattedValue
command.Connection = connection
ds.Clear()
connection.Open()
command.ExecuteNonQuery()
connection.Close()
Else
MessageBox.Show("Operation Canceled")
Exit Sub
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Try
connection.Open()
Dim str As String
str = "Select * from Operator"
adapter = New SqlDataAdapter(str, connection)
adapter.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Try