Results 1 to 13 of 13

Thread: who is wrong me or ADO ? {Sorted }

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Unhappy who is wrong me or ADO ? {Sorted }

    I am using this code to save info written in textboxes to db .Everything seem to be fine but I don't know why it keeps throwing error saying "error in insert syntax "
    the error happens while reaching update line.
    Help plz
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, _
    2.  ByVal e As System.EventArgs) Handles Button1.Click
    3.  
    4.         Dim MySQLStr As String = "Select * From MyTab"
    5.         Dim Mypath As String = Application.StartupPath & "\webdb.mdb"
    6.         Dim MyCon As New OleDbConnection _
    7. ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Mypath)
    8.         Dim myadap As New OleDb.OleDbDataAdapter(MySQLStr, MyCon)
    9.         Dim objCmdBld As New OleDb.OleDbCommandBuilder(myadap)
    10.         Dim ds As DataSet = New DataSet()
    11.         MyCon.Open()
    12.  
    13.         myadap.Fill(ds, "mytab")
    14.         Dim MyDataRow As DataRow = ds.Tables("mytab").NewRow
    15.  
    16.         MyDataRow("URL") = Trim(TextBox1.Text)
    17.         MyDataRow("Category") = Trim(TextBox2.Text)
    18.         MyDataRow("Language") = Trim(TextBox3.Text)
    19.         MyDataRow("UserName") = Trim(TextBox4.Text)
    20.         MyDataRow("Password") = Trim(TextBox5.Text)
    21.         MyDataRow("Comment") = Trim(TextBox6.Text)
    22.         MyDataRow("last") = Trim(TextBox7.Text)
    23.  
    24.         ds.Tables("MyTab").Rows.Add(MyDataRow)
    25.         Try
    26.             myadap.Update(ds, "mytab")
    27.         Catch x As Exception
    28.             MsgBox(x.Message)
    29.         End Try
    30.         MyCon.Close()
    31.     End Sub
    Last edited by Pirate; Jan 18th, 2003 at 08:15 PM.

  2. #2

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    there is one table called "MyTab" and 7 columns all in XP access db.

  3. #3
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brisbane Australia
    Posts
    150

    access

    I've experienced similar problems with what access thinks are 'reserved words' on an Insert statement. Try prefixing the fields in your database with say f_ and see if the error goes away. I'm thinking it might not like words like field names like password etc

    regards

    BH

  4. #4
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  5. #5

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I tried every way to get it to work but it seems as you said guys.
    thanx a lot , and you Psyrus for the links .
    Last edited by Pirate; Jan 18th, 2003 at 08:14 PM.

  6. #6

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    exactly what you said is true . I am sure this bug or whatever wasn't exist in the old ADO (vb6). nobody understands M$.

  7. #7
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brisbane Australia
    Posts
    150

    access problems

    You are right. The problem dosn't appear to exist in ADO - it even works in Datareaders - it appears it only rears its ugly head when you are trying to INSERT or UPDATE thru disconnected Datasets. I've prefixed every field with the table name - eg Name is now EM_Name if an Employer table.

    Found this was the only way to solve the problem.

    regards
    Brian

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    When a field is the same as a keyword or has a space or funky character sometimes it works if you enclose it in [].

    [Password]

  9. #9

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Sometimes ??

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yes it depends what the actual error is. If it is just not recognizing the field name then that usually works.

  11. #11

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    What I am asking now is If I enclosed the field name with this brackets [ ] I shouldn't get any error .? right ?

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well I guess what I'm saying is you shouldn't BUT I haven't tested it enough to say for sure.

  13. #13

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    never mind . for sure I would change every reserved keyword I used in my proj to something a little bit different . thanx for care

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