Click here to Skip to main content
15,887,355 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On trying to update the data in access database..no error is displayed yet the data does not get updated...what could be wrong? here is some of the code under the update button.
VB
connect()

'checking wherether centre number exists in database
Try
    If Not cnn.State = ConnectionState.Open Then
        'open connection if it is not yet open
        cnn.Open()
    End If

    cmd.Connection = cnn

    cmd.CommandText = "SELECT count(motonum) from moto where motonum = '" & TextBox1.Text & "'"

    myData = cmd.ExecuteReader

    While myData.Read()
        dcount = myData(0)
    End While
    myData.Close()
    'if number exists.......
    MessageBox.Show(dcount)
    If dcount <> 0 And Me.TextBox1.Text <> Me.TextBox1.Tag Then
        MsgBox("Centre number " & TextBox1.Text + " is Already Registered. Please Try another Number!", MsgBoxStyle.Critical)
        'if number doesnt exist......update
    Else

        cmd.CommandText = "UPDATE moto " & _
                        " SET motonum='" & Me.TextBox1.Text & _
                        "', motocat='" & Me.TextBox1.Text.Trim & "'" & _
                        "where motonum='" & Me.TextBox1.Tag & "'"
        cmd.ExecuteNonQuery()
        MessageBox.Show("updated")

    End If

Catch ex As Exception
    MessageBox.Show(ex.ToString)
End Try
Posted
Updated 19-Jan-13 0:04am
v2

1 solution

Who knows? You don't - and we don't - and none of us can find out, because you are throwing away any and all information on the cause of the error.

When you use an empty Catch block, you are saying "I don't care what the error is, let's ignore it and continue".

Add some code - at a bare minimum:
VB
Catch ex As Exception
    MessageBox.Show(ex.Message)
End Try
Which will give you a start of finding what the problem is caused by!
 
Share this answer
 
Comments
braop 19-Jan-13 6:07am    
Thankx. With that included no single error is displayed ...MessageBox.show("updated") is displayed but value isn't updated
OriginalGriff 19-Jan-13 6:18am    
Are you sure?
Check your connection string, and look at that exact database - make certain that it is exactly the database file you think it is.
If you have added the DB as a project file, then it is possible that the DB is copied to your debug directory every time the project is run, or that there is a copy of the DB that you are updating, and you are checking via the original version.

BTW: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900