Inserting, Updating and Variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ANGELSDAGGER
    New Member
    • Aug 2007
    • 14

    #1

    Inserting, Updating and Variables

    Is it possible to INSERT a new row into a database and then place the value of a variable into it?

    I'm using VB.NET and an Access database.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by ANGELSDAGGER
    Is it possible to INSERT a new row into a database and then place the value of a variable into it?

    I'm using VB.NET and an Access database.
    Please review the .NET article on How to use a database in your program .

    For your Access database, you will need to us the System.Data.Ole Db namespace in order to connect to the Access database
    [code=vbnet]
    Imports System.Data.Ole Db
    [/code]

    You will need a connection string....

    Then you need to create a command object....
    [code=vbnet]
    Dim cmd As New OleDbCommand("I NSERT INTO MyTable(Var1, Var2)VALUES('" & Var1Value & "','" & Var2Value & "')", New OleDbConnection (connectionStri ng))
    [/code]

    Then you need to carry out your command...
    [code=vbnet]
    cmd.Connection. Open()
    cmd.ExecuteNonQ uery()
    cmd.Connection. Close()
    [/code]


    Cheers

    -Frinny

    Comment

    Working...