Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,390 VB.NET Programmers. There are 1,366 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Oledb Exception

 
Reply to this topicStart new topic

Oledb Exception, catches oledb exception and shows a msgbox syntax error in insert into

krazzy4
post 7 May, 2008 - 09:43 PM
Post #1


New D.I.C Head

*
Joined: 1 May, 2008
Posts: 15



i hav got a oledb error each time while inserting or updating but select statements are perfectly working pls ny1 can solv my probl..
CODE
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
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


jjsaw5
post 8 May, 2008 - 05:12 AM
Post #2


D.I.C Addict

Group Icon
Joined: 4 Jan, 2008
Posts: 541

please use [code] tags when posting code.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

jayman9
post 8 May, 2008 - 08:31 AM
Post #3


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 5,566

Post the error message that you are receiving.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

baavgai
post 8 May, 2008 - 08:54 AM
Post #4


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,078

A fullName like "Tom O'Bedlam" will fry your code. Consider binding your paramters.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

krazzy4
post 9 May, 2008 - 01:04 AM
Post #5


New D.I.C Head

*
Joined: 1 May, 2008
Posts: 15

i m using Microsoft Access 2000 version and working on Visual studio 2005.....
i hav put a try and catch block in my coding so when i run my application and trying to insert the data ...a msgbox opens titled as Oledb error and the message is : "Syntax error in INSERT INTO statement.".......

yes i tried many times with inserting only first name without any space in the fullname textbox.....but the probl remains unsolved.....


what should i do...
Pls somone help me...[sad.gif]
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 04:56AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month