#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    31
    Rep Power
    3

    Insert to a SQL Table using ADODB Connection


    Hi,

    I have the below code for Inserting to a SQL database.

    Const DB_CONNECT_STRING = "Provider=SQLOLEDB;Data Source=xxxxx;Initial Catalog=xx;User ID=xx;Password=xx"

    Set myConn = CreateObject("ADODB.Connection")

    Set myCommand = CreateObject("ADODB.Command")

    myConn.OPEN DB_CONNECT_STRING

    set myCommand.ActiveConnection = myConn

    myCommand.ComandText = "Insert into DB_TABLE values(strDlist, objMember.SamAccountName)"

    myCommand.Execute

    myConn.Close


    This code works by itself

    2 Questions :

    1. How can I put some Error check to see it is able to open the database or to report the issue.

    2. How to email the # of rows it inserted.

    Any sample code if someone has and can provide would be great.

    Regards-
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,430
    Rep Power
    4539
    Error trapping is different between versions of VB, but is well documented in all versions. Check the documentation for your VB version.

    Getting the # of rows affected by a sql statment is probably dependent on the type of dbms you're using. I think sql server returns a "rows affected" value as a return parameter, but I don't know how to grab the value from vb code.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo