how I should proceed to get all active PSOs on a specific domain.
I know that this domain contains the following PSOs:
CN=PSO-Standard
CN=PSO-Sensitive
But I must create a report to display them so I must load them in dynamic way.
I guess there is a kind of filter to get the PSO container and then loop through its recordset.
e.g.
.filter = "(CN=Password Settings Container)"
.attributes = "msDS-PasswordSettingsContainer"
thx in advance.
using classic asp with vbscript
The filter you are looking for is : "(objectClass=msDS-PasswordSettings)"
Here is a sample Vbscript to test :
'==========================================================================
'
' NAME: SearchPSO.vbs
'
' AUTHOR: JPB , Silogix
' DATE : 29/06/2011
'
' COMMENT:
'
'==========================================================================
Option Explicit
Dim machine
Dim oRootDSE ' Root Directory Service Specific Entry
Dim DomainContainer ' The Roor of the Domain
Dim conn ' ADODB connexion
Dim ldapBase ' Base DN of the search
Dim ldapFilter ' Search filter
Dim ldapAttributes ' Attributs to get
Dim ldapScope ' Search scope
Dim ldapStr ' String to execute
Dim rs ' Search result
Dim f '
Dim oADSI ' ADSI access
' ADODB cooking
machine = "WM2008R2ENT"
Set oRootDSE = GetObject("LDAP://"&machine&"/"&"RootDSE")
DomainContainer = oRootDSE.Get("defaultNamingContext")
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Properties("User ID") = "jpb"
conn.Properties("Password") = "test.2011"
conn.Properties("Encrypt Password") = True
conn.Open "ADs Provider"
' Building the request to exécute
ldapBase = "<LDAP://" & machine &"/"& DomainContainer & ">"
ldapFilter = "(objectClass=msDS-PasswordSettings)"
ldapAttributes = "cn,msDS-LockoutDuration,msDS-MaximumPasswordAge"
ldapScope = "subtree"
ldapStr = ldapBase&";"&ldapFilter&";"&ldapAttributes&";"&ldapScope
' Search request execution
Set rs = conn.Execute(ldapStr)
' Restitution du résultat
While Not rs.EOF
'For each f in rs.Fields
' WScript.Echo f.Name & ":" & f.Value
'Next
WScript.Echo rs.Fields("cn").Value
rs.MoveNext
Wend
Related
Holiday Database
I need to know how many people in a particular department are off, so new holiday requests can either be "Approved" or "Rejected"
Table
This is the Table_Add_Holidays
Data for Department
Test Data with 2 departments
Data for the Approved
Just sample Data
I used a Query to perform this it worked then after I changed other code elsewhere it stopped working. So I restarted from scratch using the above code and this doesn't work as I thought it would.
I want to filter the data by "Approved" first then
I want to filter by "Department" so I can get a record count of how many people are off in the department
Any help would be appreciated
TIA
' Dim rstQuery As DAO.Recordset
' Dim rstQuery2 As DAO.Recordset
Dim rstQuery As DAO.Recordset2
Dim rstQuery2 As DAO.Recordset2
On Error GoTo ErrorHandler
' I was using a Query but when I tried "Set rstQuery = rstQuery2.OpenRecordset" I had a mis match
' rstQuery - was RecordSet
' rstQuery2 - whilst this was was RecordSet2
'
' Set rstQuery2 = CurrentDb.OpenRecordset("SELECT * FROM [Query_Table_Add_Holidays_CountOff_General]")
Set rstQuery2 = CurrentDb.OpenRecordset("SELECT * FROM [Table_Add_Holidays]")
rstQuery2.Filter = "StatusOfRequest = 'Approved'"
FindRecordCount = rstQuery2.RecordCount
rstQuery2.Filter = "Department = '" & oDept & "'"
FindRecordCount = rstQuery2.RecordCount
' Set rstQuery = rstQuery2.OpenRecordset
Set rstQuery = rstQuery2
If rstQuery.EOF Then
FindRecordCount = 0
Else
rstQuery.MoveLast
FindRecordCount = rstQuery.RecordCount
End If
rstQuery.Close
Set rstQuery = Nothing
You could DCount:
HolidayCount = DCount("*", "[Table_Add_Holidays]", "StatusOfRequest = 'Approved' And Department = '" & oDept & "'")
How to add multiple email addresses in CC list for VB Script send mail.
option explicit
' --------------------------------------------------------------------------
' -- Create Lotus Notes email (and add attachment) using VB Script
' --
' -- Version 1.01
' --
' -- Created by : Michael Green
' -- migreen#westpac.com.au
' --
' -- Based on in-complete/partially working script from :
' -- http://en.allexperts.com/q/Using-Lotus-Notes-1427/Creating-LotusNotes-email-using-1.htm
' --
' -- Created : 06/10/2009
' -- Last Updated: 07/10/2009
' --------------------------------------------------------------------------
Dim oSession ' AS NotesSession
Dim strServer
Dim strUserName
Dim strMailDbName
Dim oCurrentMailDb ' as NOTESDATABASE
Dim oMailDoc ' as NOTESDOCUMENT
Dim ortItem ' as NOTESRICHTEXTITEM
Dim ortAttacment ' as NOTESRICHTEXTITEM
Dim oEmbedObject ' as ????
dim cstrAttachment
Dim blAttachment
cstrAttachment = "c:\Temp\Telstra.xls"
blAttachment = True
' Start a session to notes
wscript.echo "## Connecting to Lotus Notes session..."
Set oSession = CreateObject("Notes.NotesSession")
wscript.echo("NotesVersion : " & oSession.NotesVersion)
wscript.echo("NotesBuildVersion: " & oSession.NotesBuildVersion)
wscript.echo("UserName : " & oSession.UserName)
wscript.echo("EffectiveUserName: " & oSession.EffectiveUserName)
wscript.echo "## GetEnvironmentString..."
strServer = oSession.GetEnvironmentString("MailServer",True)
wscript.echo("Server :" & strServer)
' eg. CN=Michael V Green/OU=CORPAU/OU=WBCAU/O=WBG
strUserName = oSession.UserName
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
wscript.echo("MailDbName :" & strMailDbName)
wscript.echo "## Getting current Notes database..."
' open the mail database in Notes
set oCurrentMailDb = oSession.CurrentDatabase
wscript.echo("fileName:" & oCurrentMailDb.fileName)
wscript.echo("filePath:" & oCurrentMailDb.filePath)
wscript.echo("server:" & oCurrentMailDb.server)
wscript.echo("Title:" & oCurrentMailDb.Title)
If oCurrentMailDb.IsOpen = True Then
' Already open for mail
wscript.echo "## Lotus Notes mail database is already open !"
Else
wscript.echo "## Opening Lotus Notes mail database..."
oCurrentMailDb.OPENMAIL
End If
' Create a document in the back end
Set oMailDoc = oCurrentMailDb.CREATEDOCUMENT
' Set the form name to memo
OMailDoc.form = "Memo"
with oMailDoc
.SendTo = "migreen#westpac.com.au"
.BlindCopyTo = "mgreen#ozemail.com.au"
.CopyTo = "migreen#westpac.com.au"
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
set ortItem = oMaildoc.CREATERICHTEXTITEM("Body")
with ortItem
.AppendText("Test of RTF Item append")
.AddNewLine(2)
.AppendText("Signature")
End With
' Create additional Rich Text item and attach it
If blAttachment Then
Set ortAttacment = oMailDoc.CREATERICHTEXTITEM("Attachment")
' Function EMBEDOBJECT(ByVal TYPE As Short, ByVal CLASS As String, ByVal SOURCE As String, Optional ByVal OBJECTNAME As Object = Nothing) As Object
' Member of lotus.NOTESRICHTEXTITEM
Set oEmbedObject = ortAttacment.EMBEDOBJECT(1454, "", cstrAttachment, "Attachment")
End If
wscript.echo "## Sending email..."
with oMailDoc
.PostedDate = Now()
.SAVEMESSAGEONSEND = "True"
.send(false)
end with
wscript.echo "## Sent !"
' close objects
set oMailDoc = nothing
set oCurrentMailDb = nothing
set oSession = nothing
Just use an array to set the values
with oMailDoc
.SendTo = Array( "migreen#westpac.com.au", "mgreen#westpac.com.au", "green#westpac.com.au" )
.BlindCopyTo = "mgreen#ozemail.com.au"
.CopyTo = "migreen#westpac.com.au"
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
Originally I did not want to comment on the quality of the copied code at all. But the discussion with Lankymart made me think, it would be good to comment on it.
Set oSession = CreateObject("Notes.NotesSession")
This line creates an OLE interface to a running Notes- Client. If client does not run, then it will be started. If you used Set oSession = CreateObject("Lotus.NotesSession") then it would have been a COM- Object you get. Be aware, that Some OLE- Methods do not work in COM and vice versa. e.g. oCurrentMailDb.OPENMAIL is OLE, while the same thing in COM would be oCurrentMailDb.OpenMailDatabase()
' eg. CN=Michael V Green/OU=CORPAU/OU=WBCAU/O=WBG
strUserName = oSession.UserName
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
Getting the users' mailfile is completely nonsense, the code will get everything but a correct filename. As the variable is not used at all - can be forgotten
set oCurrentMailDb = oSession.CurrentDatabase
Just gets the database that is currently open in the client. If no database is open, an error will be thrown in the next wscript.echo- line, and we will never get to the next lines where it checks, if a database is open...
The problem with this line: Sending mails is possible from ANY database in Lotus Notes. If the database that is open e.g. is the personal addressbook, then the mail will be saved and sent from there (and you will never find it in the Sent- View of your mailfile.
I would suggest to use OPENMAIL first and only do a fallback to the currently open database if that fails.
The rest of the code seems to be OK.
Create an array of email address strings and set CopyTo to that array:
Dim addresses (2)
addresses(0) = "EMAIL"
addresses(1) = "EMAIL"
addresses(2) = "EMAIL"
with oMailDoc
.SendTo = "migreen#westpac.com.au"
.BlindCopyTo = "mgreen#ozemail.com.au"
.CopyTo = addresses
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
I need to have an Active Directory Shadow Groups (aka Active Directory Dynamic Group), based on several DN's.
I've searched high and low for a simple tool that would allow me to do this, and finally found Dan Holme's excellent script (quoted below) at http://kb.caresys.com.cn/4052785/need-script-add-all-accounts-active-directory-security-group (and a few other places)
I also found several PowerShell scripts, but they all appear to have much harder dependencies and I need a tool that's as stand-alone as possible. They also all have the same problem as I'm faced with here.
The Group_Shadow.vbs script performs exactly what I need with one exception:
I need to be able to specify the AD's Host, port number and credentials (login and password).
The script assumes that "LDAP://" is pointing to the correct AD, and I guess the AD Credentials are derived from the user running the script?
I did find a hint about how to set the host name and password, by changing the "LDAP://" string into "LDAP://LDAP_HOST:LDAP_PORT/".
That seems pretty easy to implement - but there were a few comments stating it didn't work...
I also found a hint about setting the credentials:
Dim LDAP ' As IADsOpenDSObject
Set LDAP = GetObject("LDAP:")
Set obj = LDAP.OpenDSObject("LDAP://", "domain\name", "password", ADS_USE_ENCRYPTION OR ADS_SECURE_AUTHENTICATION)
This appear to be the hard part (being totally novice in both the VBScript and Active Directory world), and I simply can't figure out how to combine to two.
I hope the community can help me out, either by assisting fixing this script or by pointing to a different solution.
Thanks in advance!
The Script:
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME: Group_Shadow.vbs
'
' AUTHOR: Dan Holme , Intelliem
' DATE : 12/12/2007
'
' USAGE:
' cscript.exe Group_Shadow.vbs
'
' Dynamically updates the membership of a group
' to match the objects returned from an Active Directory query
'
' See the Windows Administration Resource Kit for documentation
'
' Neither Microsoft nor Intelliem guarantee the performance
' of scripts, scripting examples or tools.
'
' See www.intelliem.com/resourcekit for updates to this script
'
' (c) 2007 Intelliem, Inc
'==========================================================================
Option Explicit
Dim sDomainDN
Dim sGroupSAMAccountName
Dim aSearchOUs
Dim sQuery
'==========================================================================
' CONFIGURATION BLOCK
' Domain's DN
sDomainDN = "dc=domain,dc=local"
' sAMAccountName of shadow group
sGroupSAMAccountName = "Security Group"
' An array of one or more OUs to search
aSearchOUs = Array("ou=Something,dc=domain,dc=local")
' LDAP query that will be run in each OU
sQuery = " (&(objectCategory=computer)(name=GA*));distinguishedName;subtree"
'==========================================================================
' Create dictionaries
Dim dResults
Set dResults = CreateObject("Scripting.Dictionary")
dResults.CompareMode = vbTextCompare ' Case INsensitive
Dim dTargetMembership
Set dTargetMembership = CreateObject("Scripting.Dictionary")
dTargetMembership.CompareMode = vbTextCompare ' Case INsensitive
Dim dCurrentMembership
Set dCurrentMembership = CreateObject("Scripting.Dictionary")
dCurrentMembership.CompareMode = vbTextCompare ' Case INsensitive
Dim dMembershipChanges
Set dMembershipChanges = CreateObject("Scripting.Dictionary")
dMembershipChanges.CompareMode = vbTextCompare ' Case INsensitive
' Perform LDAP searches, adding to final list stored in dTargetMembership
Dim sSearchOU
Dim sLDAPQuery
For Each sSearchOU In aSearchOUs
sLDAPQuery = "<LDAP://" & sSearchOU & ">;" & sQuery
Set dResults = AD_Search_Dictionary(sLDAPQuery)
Call DictionaryAppend(dResults, dTargetMembership)
Next
' Locate group
Dim sGroupADsPath
Dim oGroup
sGroupADsPath = ADObject_Find_Generic(sGroupSAMAccountName, sDomainDN)
If sGroupADsPath = "" Then
' Error handling: group not found
WScript.Quit
End If
Set oGroup = GetObject(sGroupADsPath)
' Get members and store in dictionary
Dim aMembers
aMembers = oGroup.GetEx("member")
Set dCurrentMembership = ArrayToDictionary(aMembers)
' Calculate the "delta" between the current and desired state
Set dMembershipChanges = Dictionary_Transform(dCurrentMembership, dTargetMembership)
' Make the membership changes based on the transform dictionary's instructions
Dim sMember
For Each sMember In dMembershipChanges
If UCase(dMembershipChanges.Item(sMember)) = "ADD" Then
oGroup.Add "LDAP://" & sMember
End If
If UCase(dMembershipChanges.Item(sMember)) = "DELETE" Then
oGroup.Remove "LDAP://" & sMember
End If
Next
WScript.Quit
' ======================
' FUNCTIONS FROM LIBRARY
' ======================
' #region Dictionary routines
Function ArrayToDictionary(ByRef aArray)
' Converts a one-dimensional array into a dictionary.
' Assumes elements in array are unique
Dim dDic
Dim aElement
Set dDic = CreateObject("Scripting.Dictionary")
dDic.CompareMode = vbTextCompare ' Case INsensitive
On Error Resume Next ' trap duplicate array elements
For Each aElement In aArray
dDic.Add aElement, 0
Next
On Error GoTo 0
Set ArrayToDictionary = dDic
End Function
Sub DictionaryAppend(ByRef dNewElements, ByRef dDictionary)
' Appends the elements of dNewElements to dDictionary
Dim sKey
On Error Resume Next ' trap duplicate array elements
For Each sKey In dNewElements.keys
dDictionary.Add sKey, dNewElements.Item(sKey)
Next
On Error GoTo 0
End Sub
Function Dictionary_Transform(ByVal dOriginal, ByVal dFinal)
' Retunrs a dictionary with a list of update operations required
' so that dOriginal is transformed to dFinal
Dim dTransform, sKey
Set dTransform = CreateObject("Scripting.Dictionary")
dTransform.CompareMode = vbTextCompare ' Case INsensitive
For Each sKey In dFinal.Keys
If Not dOriginal.Exists(sKey) Then
dTransform.Add sKey, "ADD"
End If
Next
For Each sKey In dOriginal.Keys
If Not dFinal.Exists(sKey) Then
dTransform.Add sKey, "DELETE"
End If
Next
Set Dictionary_Transform = dTransform
End Function
' #endregion
' #region Active Directory object find routines
Function ADObject_Find_Generic(ByVal sObject, ByVal sSearchDN)
' Version 071130
' Takes any input (name, DN, or ADsPath) of a user, computer, or group, and
' returns the ADsPath of the object as a way of validating that the object exists
'
' INPUTS: sObject DN or ADsPath to an object
' sAMAccountName (pre-Windows 2000 logon name) of a user or group
' computer name of a computer
' sSearchDN the DN within which to search (often, the DN of the domain, e.g. dc=contoso, dc=com)
'
' RETURNS: ADObject_Find_Generic ADsPath (LDAP://...) of the object
' blank if object was not found
'
' NOTES: ASSUMPTION: computers, users & groups have unique names. See note inline.
'
' REQUIRES AD_Search_Array routine
' AD_Search_RS routine
' ADObject_Validate routine
Dim aResults, sLDAPQuery
Select Case ADObject_NameType(sObject)
Case ""
ADObject_Find_Generic = ""
Case "adspath"
ADObject_Find_Generic = ADObject_Validate(sObject)
Case "distinguishedname"
ADObject_Find_Generic = ADObject_Validate("LDAP://" & sObject)
Case "name"
' Assumption: No computer has the same name as a user's or group's sAMAccountName
' otherwise, this query will return more than one result
sLDAPQuery = "<LDAP://" & sSearchDN & ">;" & _
"(|(samAccountName=" & sObject & ")(samAccountName=" & sObject & "$));" & _
"aDSPath;subtree"
aResults = AD_Search_Array (sLDAPQuery)
If Ubound(aResults) = -1 Then
ADObject_Find_Generic = ""
Else
ADObject_Find_Generic = aResults(0)
End If
End Select
End Function
Function ADObject_NameType(ByVal sObjectName)
' Version 071204
' Evaluates sObjectName to determine what type of name it is
' Returns ADObject_NameType adspath
' distinguishedname
' name
' blank if sObjectName = ""
Dim sNameType
If Len(sObjectName) = 0 Then
sNameType = ""
ElseIf Len(sObjectName) < 3 Then
' can't be a DN or an ADsPath - must be a name
sNameType = "name"
ElseIf Ucase(Left(sObjectName,3)) = "CN=" Then
' is a DN
sNameType = "distinguishedname"
ElseIf Len(sObjectName) < 8 Then
' too short to be an ADsPath and isn't a DN, so it must be a name
sNameType = "name"
ElseIf UCase(Left(sObjectName, 7)) = "LDAP://" Then
' is already an ADsPath
sNameType = "adspath"
Else
' must be a name
sNameType = "name"
End If
ADObject_NameType = sNameType
End Function
Function ADObject_Validate(ByVal sObjectADsPath)
' Version 071122
' Returns ADsPath of object as a way of validating that the object exists
'
' INPUTS: sObjectADsPath ADsPath of object to test
' RETURNS: ADObject_Validate Path of object (if it exists) or blank
Dim oObject
On Error Resume Next
Set oObject = GetObject(sObjectADsPath)
If Err.Number <> 0 Then
ADObject_Validate = ""
Err
Turns out there are two answers to take note of in regard to "LDAP://" credentials.
First, specifically to the script I posted, I simply had to open my eyes!
Almost the last line of the script there were already options to add the credentials:
oConnection.Open "", vbNullString, vbNullString
Simply had to be correctly populated:
oConnection.Open "", "username", "password"
Second, a more general description was already provided by #Harvey Kwok in this SO answer: Secure LDAP object manipulation with VBscript using alternate credentials
I'm currently working with small-size old VB6 application.
Here is my problem : when the user clicks a button, the program is opening a connection to an Oracle Database. This works good when running from the IDE or running the .exe in Windows 95 or Windows 98 compatibility modes, otherwise it crashes.
It does work on another workstation but I don't know why (different configuration but I have no idea what that could be !)
Here is the code called when the button is pressed (it works on another workstation which has no compatibility setting set but might have some other configuration differences).
Most of the code is not related to the connection but I have let it untouched for the sake of completeness.
Private Sub Form_Load()
'
' Loads the list of printers (as defined in a table of the SQL DB)
'
On Error GoTo error_handler
' icon
Screen.MousePointer = vbHourglass
'Dim conn As New adodb.Connection
'Dim cmd As New adodb.Command
'Dim rcs As New adodb.Recordset
Dim conn As adodb.Connection
Dim cmd As adodb.Command
Dim rcs As adodb.Recordset
Set conn = New adodb.Connection
Set cmd = New adodb.Command
Set rcs = New adodb.Recordset
'Dim fs As New FileSystemObject
Dim fs As FileSystemObject
Set fs = New FileSystemObject
Dim fic As File
Dim texte As textStream
Dim req As String
Dim i As Integer
Dim chem As Variant
Dim buffer As String
Dim retstring As String
Dim rc As Long
If fs.FileExists(Appli_Rep & "Queries\System\printers_list.txt") Then
Set fic = fs.GetFile(Appli_Rep & "Queries\System\printers_list.txt")
Set texte = fic.OpenAsTextStream(ForReading)
End If
'
' Reads connection string
'
buffer = String(145, " ")
rc = GetPrivateProfileString("Requete", "DRIVER", "1", buffer, Len(buffer) - 1, Appli_Rep & "suivi__.ini")
DoEvents
retstring = Left(buffer, InStr(buffer, Chr(0)) - 1)
'
' Gets the PATH environment variable
' So that we know where to find tnsname.ora
'
i = 0
chem = Split(Environ("TNS_ADMIN"), ";")
Do
If Len(Dir(chem(i) & "\Tnsnames.ora")) <> 0 Then
ChDrive chem(i)
ChDir chem(i)
Exit Do
End If
i = i + 1
DoEvents
Loop Until i > UBound(chem)
' Opens a connection (no DSN)
'Set conn = New adodb.Connection
conn.ConnectionString = "uid=_uid;pwd=_pwd;DRIVER=" & retstring & ";server=__PROD;"
'conn.ConnectionTimeout = 30
conn.ConnectionTimeout = 3000 ' (no change)
conn.Open ' -2147467259 [Microsoft][ODBC driver for Oracle][Oracle]ORA-06413: Connexion non ouverte
' Connexion non ouverte = french for "connection is closed".
Set cmd.ActiveConnection = conn
cmd.CommandText = texte.ReadAll
DoEvents
Set texte = Nothing
Set fic = Nothing
Set fs = Nothing
Set rcs = cmd.Execute
DoEvents
rcs.MoveFirst
Do
Me.cbo_Imprimantes.AddItem (rcs.Fields("IMPRIMANTE").Value)
rcs.MoveNext
DoEvents
Loop Until rcs.EOF
' Close connections / free objects
Set rcs = Nothing
Set cmd = Nothing
If conn.State = 1 Then
conn.Close
End If
Set conn = Nothing
' icon back to normal
Screen.MousePointer = vbDefault
Exit Sub
error_handler:
' retour normal
Screen.MousePointer = vbDefault
If Err.Number <> 0 Then
MsgBox Err.Number & " " & Err.Description, vbCritical + vbOKOnly, "Erreur !!!"
MsgBox Err.Source
End If
On Error Resume Next
' Fermeture des objets
Set rcs = Nothing
Set cmd = Nothing
Set conn = Nothing
Set texte = Nothing
Set fic = Nothing
Set fs = Nothing
End Sub
It crashes on the "conn.Open" statement.
The connection string is identical in both cases (I have displayed it in a messagebox to be sure that 'retstring' is valid).
Thanks for your time.
i have a drop down box , it has value that is retrieve from datasqlsource, however i want to get the count value on page load but it seem that it did not count
'Dim adapter As New SqlDataAdapter
'Dim ds As New DataSet
'Dim connectionString = ConfigurationManager.ConnectionStrings("myProject").ConnectionString
'Dim myConn As New SqlConnection(connectionString)
'Dim cmd = "SELECT * FROM Group Where groupID='" & DropDownList1.SelectedValue & "' AND customerID='" & Session("customerID") & "'"
'Try
' myConn5.Open()
' Dim myCmd5 As New SqlCommand(cmd5, myConn5)
' adapter.SelectCommand = myCmd5
' adapter.Fill(ds, "Group")
' ' txtQuan.Text = adapter.SelectCommand.ExecuteScalar().ToString()
' adapter.Dispose()
' myCmd5.Dispose()
' ' txtQuan.Text = ds.Tables(0).Rows.Count
' If ds.Tables(0).Rows.Count >= 10 Then
' lblNoPpl.Text = "The group is full"
' Else
' Dim numLefts As Integer = 10 - ds.Tables(0).Rows.Count
' lblNoPpl.Text = numLefts.ToString() + "space left"
'Catch ex As Exception
' MsgBox("Can not open connection ! ")
'End Try
if you use cmd.ExcuteScalar() method retrieve a count,the sql should be
SELECT COUNT(*) FROM Group Where groupID='" & DropDownList1.SelectedValue & "' AND customerID='" & Session("customerID") & "'"