CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2015
    Posts
    5

    Unable to delete record from Ms.Acess using Vb.net

    Hello , I am making a project on railway reservation system in which if a user wants to cancel his ticket , he should enter his phone number and ticket number , after that he ticket will get cancelled . The problem I am getting is that it is displaying that your ticket has been cancelled but t is not actually deleting the record from the database . Phone is string and Tnumber is in numeric . Thank you !
    Code:
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim okToDelete As MsgBoxResult = MsgBox("Are you sure you want to cancel your ticket?", MsgBoxStyle.YesNo)
            If okToDelete = MsgBoxResult.Yes Then
                Dim str As String
                str = "Delete from Table2 Where Phone = ' " & TextBox1.Text & " ' and Tnumber= " & TextBox2.Text
                Dim cmd As OleDbCommand = New OleDbCommand(str, Conn)
                Try
                    cmd.ExecuteNonQuery()
                    cmd.Dispose()
                    Conn.Close()
    
                    MsgBox("Your Ticket Cancelled Sucessfully ! ")
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            ElseIf okToDelete = MsgBoxResult.No Then
            End If
    
            Form3.Show()
            Me.Close()
        End Sub

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Unable to delete record from Ms.Acess using Vb.net

    I think this one has already been resolved over at vbforums but the issue here seems to be the extra spaces being added to the ends of the phone number when the string is built

    ' " & TextBox1.Text & " '
    Always use [code][/code] tags when posting code.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured