October 24th, 2012, 09:04 PM
Insert to a SQL Table using ADODB Connection
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")
set myCommand.ActiveConnection = myConn
myCommand.ComandText = "Insert into DB_TABLE values(strDlist, objMember.SamAccountName)"
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.
October 25th, 2012, 09:50 PM
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.
I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton