Submitted By: Derrick Walker

Sample script demonstrating how to use ADO to retrieve data from a SQL Server database.

Visual Basic
Edit|Remove
		Dim EmailUser
		Dim objConn
		Dim objCmd
		Dim objRS

		Set objConn = CreateObject("ADODB.Connection")
		Set objCmd = CreateObject("ADODB.Command")
		Set objRS = CreateObject("ADODB.RecordSet")
		Identifier = "ERROR"

		'objConn.Open "Provider=SQLOLEDB.1;Data Source=113.130.193.175;Initial Catalog=nfm_report_system_baseline","sa","dfs021"
		objConn.Open "Provider=SQLOLEDB.1;Data Source=ideasql2005;Initial Catalog=goal_owner_dev","sa","Dfssvr55"

		objCmd.CommandText = "SELECT EML_ADDR FROM sysEML_LST WHERE ACTIVITY = '" & Identifier & "'"

		Set objCmd.ActiveConnection = objConn

		objRS.Open objCmd

		While Not objRS.EOF

			EmailUser = EmailUser & objRS("EML_ADDR") & ";" 

		objRS.MoveNext

		Wend

		If Not Len(EmailUser) < 1 Then
			EmailUser = Left(EmailUser, Len(EmailUser)-1)
		Else
			EmailUser = "email name"
		End If

		GetEmailUser = EmailUser

		objConn.close
		Set objCmd = Nothing
		Set objRS= Nothing