Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.4 KiB

  1. set objDBConnection = Wscript.CreateObject("ADODB.Connection")
  2. set RS = Wscript.CreateObject("ADODB.Recordset")
  3. SERVER = InputBox("Enter the name of the SQL Server you wish to connect to"&vbcrlf&vbcrlf&"This SQL Server must have the Northwind sample database installed.", "Connect to SQL Server...")
  4. IF LEN(TRIM(SERVER)) = 0 THEN
  5. MsgBox "You did not enter the name of a machine to query. Exiting script.", vbCritical, "No machine requested."
  6. WScript.Quit
  7. END IF
  8. USERNAME = InputBox("Enter the name of the SQL Server username to query with", "Enter SQL username...")
  9. IF LEN(TRIM(USERNAME)) = 0 THEN
  10. MsgBox "You did not enter the SQL Server username to query with. Exiting script.", vbCritical, "No username specified."
  11. WScript.Quit
  12. END IF
  13. PWD = InputBox("Enter the password of the SQL Server you wish to connect to"&vbcrlf&vbcrlf&"Leave blank if no password is needed.", "Enter SQL password...")
  14. SQLQuery1 ="SELECT Employees.FirstName AS FirstName, Employees.City AS City FROM Employees WHERE Employees.Lastname = 'Suyama'"
  15. objDBConnection.open "Provider=SQLOLEDB;Data Source="&SERVER&";Initial Catalog=Northwind;User ID="&USERNAME&";Password="&PWD&";"
  16. Set GetRS = objDBConnection.Execute(SQLQuery1)
  17. IF GetRS.EOF THEN
  18. MsgBox "No employees were found with the last name you searched on!"
  19. ELSE
  20. Do While Not GetRS.EOF
  21. MsgBox "There is an employee in "&GetRS("City")&" named "&GetRS("FirstName")&" with the last name you searched on."
  22. GetRS.MoveNext
  23. Loop
  24. END IF