Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
If MessageBox.Show("Are you sure to delete?", "Confirm.", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then
Dim strID As String = Me.dgName(0, Me.dgName.CurrentCell.RowIndex).Value.ToString()
Dim myConnection As SqlCeConnection
'myConnection = New SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\Database1.sdf;"))
myConnection = New SqlCeConnection("Data Source=C:\WindowsFormsApplication\WindowsFormsApplication\Database1.sdf;")
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "DELETE FROM [mytable] WHERE id = '" & strID & "'"
myCommand.CommandType = CommandType.Text
myCommand.ExecuteNonQuery()
myConnection.Close()
MessageBox.Show("Delete Successfully")
BindDataGrid()
End If
End Sub