cmd.executenonquery()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • preedhu
    New Member
    • Apr 2010
    • 1

    #1

    cmd.executenonquery()

    To insert a data into the data base, to the best of my knowledge the code i have written is correct.. but i frequently get this error.. hope I will receive a proper solution for my query.

    The code is:

    Code:
    imports system.data.oledb
    
    dim cn as new oledbconnection
    dim cmd as new oledbcommand
    
    under the insert button:
    cn.open()
    cmd.connection=cn
    cmd.connectionstring=""
    cmd.commandtype=data.commandtype.text
    cmd.commandtext="insert into tablename values("")"
    msgbox("inserted")
    cn.close()
    thanks,
    Preethy
    Last edited by Frinavale; Apr 13 '10, 03:17 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    but i frequently get this error
    What error?

    cmd.connections tring=""
    Why is there no connectionstrin g?

    Take a look at Insight: Creating database connections without using wizards, How To Use A Database In Your Program Part I and How To Use A Database In Your Program Part II. That should help you.

    Steven

    Comment

    • semomaniz
      Recognized Expert New Member
      • Oct 2007
      • 210

      #3
      Please show us the entire code. Best way is to replace the actual table names and connection string with bogus values. And also use try catch block its really handy

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Line 11 has a problem with it.
        You cannot have:
        Code:
        cmd.commandtext="insert into tablename values("")"
        Do you see why?
        Your string is messed up.....

        You should probably review the articles that MrMancunian linked you to.

        -Frinny

        Comment

        Working...