Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

oledb Exception occurs

Last post 05-10-2008 6:57 AM by shikha_21. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 05-08-2008 6:12 AM

    • shikha_21
    • Not Ranked
    • Joined on 05-01-2008
    • India
    • New Member
    • Points 100

    oledb Exception occurs

     i hav got a oledb error each time while inserting or updating but select statements are perfectly working pls ny1 can solv my probl..
    <vb>

    Imports System.Data.OleDb

    Public Class newlogin

         Public Sub clearfields()
            txtname.Text = ""
            txtrole.Text = ""
            txtgender.Text = ""
            txtedu.Text = ""
            txtemail.Text = ""
            txtuser.Text = ""
            txtpass.Text = ""
            txtcourse.Text = ""
        End Sub


        Private Sub submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim con As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Database.mdb")
            Dim errora As Integer = 0
            Dim query As String
            If con.State = ConnectionState.Open Then con.Close()
            Try

                query = "insert into login(fullname,role,gender,education,email,username,password,course) values( '" & txtname.Text & "' , '" & txtrole.Text & "' ,  '" & txtgender.Text & "' , '" & txtedu.Text & "' , '" & txtemail.Text & "' , '" & txtuser.Text & "' , '" & txtpass.Text & "' , '" & txtcourse.Text & "' )"
                Dim cmda As New OleDbCommand(query, con)
                con.Open()
                cmda.ExecuteNonQuery()
                con.Close()
            Catch exo As OleDbException
                MsgBox(exo.Message, MsgBoxStyle.Critical, "Oledb error")
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Information, "General error")
                errora = 1
            End Try
            If Not errora = 1 Then
                MsgBox("Contact Added")
                clearfields()


            End If
            con.Close()
        End Sub

          Private Sub reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            clearfields()
        End Sub
    End Class

    </vb>

    • Post Points: 15
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 05-08-2008 6:17 AM In reply to

    • shikha_21
    • Not Ranked
    • Joined on 05-01-2008
    • India
    • New Member
    • Points 100

    Re: oledb Exception occurs

    the connection string is also declared publically in the module

    • Post Points: 10
  • 05-08-2008 9:02 AM In reply to

    • Bart_K
    • Not Ranked
    • Joined on 02-12-2008
    • United Kingdom
    • Junior Member
    • Points 195

    Re: oledb Exception occurs

    1. Which version of access are you using?

    2. What's the exact error message?

    3. Could you post the precise sql string that gets sent to the db?

    • Post Points: 5
  • 05-08-2008 9:39 AM In reply to

    • TimL
    • Top 100 Contributor
    • Joined on 07-02-2007
    • United Kingdom
    • Fanatic Member
    • Points 1,685

    Re: oledb Exception occurs

    It might be because you've called your table login and login is a reserved keyword. I'd try the following syntax change and see if it makes a difference.

     query = "insert into [login](fullname,role,gender,education,email,username,password,course) values( '" & txtname.Text & "' , '" & txtrole.Text & "' ,  '" & txtgender.Text & "' , '" & txtedu.Text & "' , '" & txtemail.Text & "' , '" & txtuser.Text & "' , '" & txtpass.Text & "' , '" & txtcourse.Text & "' )"
                

     

    • Post Points: 5
  • 05-09-2008 8:41 AM In reply to

    • shikha_21
    • Not Ranked
    • Joined on 05-01-2008
    • India
    • New Member
    • Points 100

    Re: oledb Exception occurs

    The version of Access i hav is MIcrosoft Access 2000 and the version of VB.Net i m working on is Microsoft Visual Studio 2005...

    i hav put a try and catch block in my coding so when i run my application and try to insert the data in to the login form a run time error will occur and catch stat of my coding displays a msgbox titled Oledb error......and shows  ex.message: "Syntax error in INSERT INTO statement".>>>>

    and then displays another msgbox("Contact Added")

    query = "insert into login(fullname,role,gender,education,email,username,password,course) values( '" & txtname.Text & "' , '" & txtrole.Text & "' ,  '" & txtgender.Text & "' , '" & txtedu.Text & "' , '" & txtemail.Text & "' , '" & txtuser.Text & "' , '" & txtpass.Text & "' , '" & txtcourse.Text & "' )"

    the syntax is working if i set this query into Access.

    i can't find my probl soln...

    pls help me....

    Sad

    • Post Points: 5
  • 05-09-2008 8:52 AM In reply to

    • shikha_21
    • Not Ranked
    • Joined on 05-01-2008
    • India
    • New Member
    • Points 100

    Re: oledb Exception occurs

    should i change the name of my table login to newlogin....

    if i do so then what other things i should make change in......

    • Post Points: 10
  • 05-09-2008 9:22 AM In reply to

    • Bart_K
    • Not Ranked
    • Joined on 02-12-2008
    • United Kingdom
    • Junior Member
    • Points 195

    Re: oledb Exception occurs

    Try changing the name and if that doesn't work post the actual string that gets sent to access (as in insert a breakpoint at

    Dim cmda As New OleDbCommand(query, con)

    and hover the mouse over 'query') I assume all the fields in access are Text? What's their max length?

    • Post Points: 5
  • 05-09-2008 11:29 AM In reply to

    • satyasahu
    • Not Ranked
    • Joined on 07-09-2007
    • India
    • New Member
    • Points 70

    Re: oledb Exception occurs

    Because fields like password is a keyword so it can be enclosed within square bracket [] as follow. also enclose the role and login to avoid error.

    query = "insert into [login](fullname,[role],gender,education,email,username,[password],course) values( '" & txtname.Text & "' , '" & txtrole.Text & "' ,  '" & txtgender.Text & "' , '" & txtedu.Text & "' , '" & txtemail.Text & "' , '" & txtuser.Text & "' , '" & txtpass.Text & "' , '" & txtcourse.Text & "' )"

    • Post Points: 10
  • 05-10-2008 6:57 AM In reply to

    • shikha_21
    • Not Ranked
    • Joined on 05-01-2008
    • India
    • New Member
    • Points 100

    Re: oledb Exception occurs

    thanks to all the developers..... my probl has been solved

    Thanks once againSmiley Face

    • Post Points: 5
Page 1 of 1 (9 items)