3 Replies - 265 Views - Last Post: 29 June 2013 - 10:39 AM Rate Topic: -----

#1 786_student  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-June 13

OleDbException was unhandled

Posted 29 June 2013 - 09:25 AM

Hi!

We are getting this error : 'OleDbException was unhandled' in the following code.
The error is at this place : cmd1.ExecuteNonQuery()

Also, similar code is working for updating username but not for password.

Please help !

Thanks in advance !


Imports System.Data.OleDb

Partial Public Class changepass
    Inherits System.Web.UI.Page
    Protected con As OleDbConnection
    Protected con1 As OleDbConnection

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click
        Response.Redirect("login.aspx")
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Try


        Dim str As String
        Dim cmd As OleDbCommand
        con = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\sal1.mdb")
        con.Open()
        str = "select password from login"
        cmd = New OleDbCommand(str, con)
        Dim dtr As OleDbDataReader
        dtr = cmd.ExecuteReader

        While dtr.Read
            If TextBox2.Text.Equals("") Then
                Response.Write("<script>alert('Please enter your new password !!'); window.location.href='changepass.aspx'</script>")
            End If

            If (dtr(0) = TextBox1.Text) And Not (TextBox2.Text.Equals("")) Then
                Dim str1 As String
                Dim cmd1 As OleDbCommand
                con1 = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\sal1.mdb")
                con1.Open()
                str1 = "update login set password = '" + TextBox2.Text + "'  where password = '" + TextBox1.Text + "'"
                cmd1 = New OleDbCommand(str1, con1)
                cmd1.ExecuteNonQuery()
                Response.Write("<script>alert('Passoword Changed Successfully !! '); window.location.href='changepass.aspx'</script>")

            Else
                Response.Write("<script>alert('Password does not exist.Please check your password...'); window.location.href='changepass.aspx'</script>")
                TextBox1.Text = ""
                TextBox2.Text = ""
            End If

        End While
        dtr.Close()
        con1.Close()
        con.Close()
        'Catch ex As Exception
        'Response.Write("<script>alert('ERROR'); window.location.href='changepass.aspx'</script>")
        'End Try
    End Sub

    
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: OleDbException was unhandled

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8915
  • View blog
  • Posts: 33,430
  • Joined: 12-June 08

Re: OleDbException was unhandled

Posted 29 June 2013 - 09:49 AM

Why not wrap it with a try/catch.. and put a breakpoint in the catch so you can see the full error? I see the hints of a try/catch, but for some reason they were commented out.
Was This Post Helpful? 0
  • +
  • -

#3 786_student  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-June 13

Re: OleDbException was unhandled

Posted 29 June 2013 - 10:23 AM

I tried using breakpoints in catch...Exception is caught after ' cmd1.ExecuteNonQuery()' and it shows this error : 'Syntax error in UPDATE statement.'
Was This Post Helpful? 0
  • +
  • -

#4 786_student  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-June 13

Re: OleDbException was unhandled

Posted 29 June 2013 - 10:39 AM

Hi..thanks...we got the output..!
The error was in the update statement..password was supposed be written as [password] since it is a reserved word in MS Access.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1