October 24th, 2012, 08: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, 08: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.
The man who doesn't read good books has no advantage over the man who can't read them.