0

Hi i wonder how can i delete my data using access as my database?

for example i want to delete

        Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & ConAccessDatabase & "';")
    Dim cmd As OleDbCommand


    cmd = New OleDb.OleDbCommand("delete * from [" & EBU2DB_LOB & "] where Brand ='" & Form_Month_End_Report.Combo_LOB_Brand.Text & "' & LOB ='" & Form_Month_End_Report.Combo_LOB_LOB.Text & "' & Months = '" & Form_Month_End_Report.Combo_LOB_Month.Text & "'", con)

    Dim response As String = MsgBox("Do you want Delete ? ", MsgBoxStyle.YesNo, "Confirm")
    If response = MsgBoxResult.Yes Then
        If con.State = ConnectionState.Closed Then con.Open()
        cmd.ExecuteNonQuery()
    End If

this is my code.
but nothing seem to happen to my data..

3
Contributors
3
Replies
19
Views
3 Years
Discussion Span
Last Post by ImZick
Featured Replies
  • Try this Dim cmd As New OleDbCommand("", con) cmd.CommandText = "DELETE FROM [" & EBU2DB_LOB & "] " _ & " WHERE Brand = ? " _ & " AND LOB = ? " _ & " AND Months = ? " cmd.Parameters.AddWithValue("@Brand ", Form_Month_End_Report.Combo_LOB_Brand.Text) cmd.Parameters.AddWithValue("@LOB ", Form_Month_End_Report.Combo_LOB_LOB.Text) cmd.Parameters.AddWithValue("@Months", Form_Month_End_Report.Combo_LOB_Month.Text) … Read More

  • You can do as Jim has said and shave a VERY small amount of time off by placing everything inside of the If statement: If MsgBox("Do you want to Delete?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then Dim cmd As new OleDBCommand("",con) cmd.CommandText = "DELETE FROM [" & EBU2DB_LOB & "] " … Read More

1

Try this

Dim cmd As New OleDbCommand("", con)

cmd.CommandText = "DELETE FROM [" & EBU2DB_LOB & "] " _
                & " WHERE Brand  = ? " _
                & "   AND LOB    = ? " _
                & "   AND Months = ? "

cmd.Parameters.AddWithValue("@Brand ", Form_Month_End_Report.Combo_LOB_Brand.Text)
cmd.Parameters.AddWithValue("@LOB   ", Form_Month_End_Report.Combo_LOB_LOB.Text)
cmd.Parameters.AddWithValue("@Months", Form_Month_End_Report.Combo_LOB_Month.Text)

If MsgBox("Do you want to Delete?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then
    If con.State = ConnectionState.Closed Then con.Open()
    cmd.ExecuteNonQuery()
End If
Comments
Yep.
1

You can do as Jim has said and shave a VERY small amount of time off by placing everything inside of the If statement:

If MsgBox("Do you want to Delete?", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then
    Dim cmd As new OleDBCommand("",con)
    cmd.CommandText = "DELETE FROM [" & EBU2DB_LOB & "] " _
            & " WHERE Brand  = ? " _
            & "   AND LOB    = ? " _
            & "   AND Months = ? "
    cmd.Parameters.AddWithValue("@Brand ", Form_Month_End_Report.Combo_LOB_Brand.Text)
    cmd.Parameters.AddWithValue("@LOB   ", Form_Month_End_Report.Combo_LOB_LOB.Text)
    cmd.Parameters.AddWithValue("@Months", Form_Month_End_Report.Combo_LOB_Month.Text)
    If con.State = ConnectionState.Closed Then con.Open()
    cmd.ExecuteNonQuery()
End If

This will only create the command and set the command text when you want to delete the item.

Edited by Begginnerdev

Comments
Also yep!
0

Nice it works fine :)
i just get confuse in this one

= ? "

thank you

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.