problem in deleting data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kyosuke18
    New Member
    • May 2009
    • 11

    problem in deleting data

    Hi everyone,

    I have a problem in deleting a data that is connected on the database.. I tried this code but it shows me an error: Run-time error '-2147217900(8004 0e14)': Syntax error in string in query expression 'ID=". Here is the code that i did:

    Dim cn As New ADODB.Connectio n
    Dim rs As New ADODB.Recordset
    Dim ab As String

    cn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\Docum ents and Settings\Admini strator\My Documents\sampl e adding, deleting data\sample123. mdb;Persist Security Info=False"
    rs.Open "Delete from Sample2 Where ID ='", cn, adOpenDynamic, adLockPessimist ic

    ab = MsgBox("Are you sure you want to delete a record?", vbInformation + vbYesNo, "Delete record")

    If ab = Yes Then
    If Not rs.EOF Then
    rs.Delete
    rs.Update
    MSFlexGrid1.Rem oveItem (MSFlexGrid1.Ro w)
    MsgBox "You Deleted a record!", vbOKCancel + vbInformation, "Delete"
    Else
    MSFlexGrid1.Row s = MSFlexGrid1.Fix edRows
    End If
    End If

    Also I tried other solution but only the flexgrid deletes the data and not on a database.. Here's the code:

    If MSFlexGrid1.Row s > MSFlexGrid1.Fix edRows + 1 Then
    MSFlexGrid1.Rem oveItem (MSFlexGrid1.Ro w)
    Else
    MSFlexGrid1.Row s = MSFlexGrid1.Fix edRows
    End If

    I'm using Microsoft Access 2003 as my database/backend..

    Can someone help me in my problem? In adding a record, I don't have any problem because it works already.. but in deleting a data, i can't.. I will very appreciate to those who replied on my message..

    Very Thanks,
    Kyosuke =)
  • mindgames
    New Member
    • Jan 2010
    • 1

    #2
    rs.Open "Delete from Sample2 Where ID ='" & someid & "'", cn, adOpenDynamic, adLockPessimist ic

    Use this query to delete your data.

    Comment

    Working...