|
20.12.2007, 14:53
#35023530
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
|
Вот работающее решение
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119.
<html>
<head>
<HTA:APPLICATION
ID="objMyHTA"
APPLICATIONNAME="SQL Executer"
CAPTION="yes"
SCROLL="auto"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<title>Программа выполнения запросов на SQL сервере</title>
<script language=VbScript>
'Описание переменных
Dim objConnection
Dim objRecordset
Dim strSQLCommand
Dim strConnection
strConnection = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=dbase;Data Source=sqlexpress;"
'Разремарьте необходимую строку
strSQLcommand = "SELECT * FROM PRODUCTS"
'strSQLcommand = "SELECT @@version"
'=============================================================================== Function fnMain()
fnInit()
intError = fnConnect()
If Not intError = 0 Then
MsgBox "fnConnect()", vbOkOnly, "Ошибка"
Exit Function
End If
intError = fnGetData()
If Not intError = 0 Then
MsgBox "fnGetData()", vbOkOnly, "Ошибка"
Exit Function
End If
'Process result
If objRecordset.RecordCount < 1 Then
MsgBox "No records found"
objRecordset.Close()
Else
fnResult()
End If
End Function
'===============================================================================
Function fnResult()
Dim oField
Dim vValue
strResult = "<P>"
strResult = strResult & "<div style=" & Chr( 34 ) & "background-color:white;" & _
"border:5px ridge grey" & Chr( 34 ) & ">"
strResult = strResult & "Количество записей: " & objRecordset.RecordCount & "<hr>"
strResult = strResult & "<table id=tblResult border = '1'>"
strResult = strResult & "<tr>"
For Each oField In objRecordset.Fields
strResult = strResult & "<td>" + oField.Name + "</td>"
Next
strResult = strResult & "</tr>"
Do Until objRecordset.EOF
strResult = strResult & "<tr>"
For Each oField In objRecordset.Fields
vValue = oField.Value
If IsNull( vValue ) Then vValue = "<NULL>"
strResult = strResult & "<td>" & vValue & "</td>"
Next
strResult = strResult & "</tr>"
objRecordset.MoveNext
Loop
strResult = strResult & "</table>"
strResult = strResult & "</div>"
divResult.InnerHTML = divResult.InnerHTML & strResult
objRecordset.Close
End Function
'===============================================================================
Function fnInit()
divResult.InnerHTML = ""
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
End Function
'===============================================================================
Function fnConnect()
fnConnect = 0
On Error Resume Next
objConnection.Open strConnection
If Not Err.Number = 0 Then
MsgBox "Ошибка подключения к базе данных", vbOkOnly,"Ошибка"
fnConnect = 1
Exit Function
End If
On Error Goto 0
End Function
'===============================================================================
Function fnGetData()
fnGetData = 0
On Error Resume Next
objRecordset.Open strSQLCommand,objConnection,1
If Not Err.Number = 0 Then
MsgBox "Ошибка сбора данных", vbOkOnly,"Ошибка"
fnGetData = 1
Exit Function
End If
On Error Goto 0
End Function
'===============================================================================
</script>
</head>
<body bgcolor="#C0C0C0" id=TheBody>
<div id=divSelection style="background-color:white;border:5px ridge grey">
<table width= 98 %>
<tr>
<td>
<input type = "BUTTON" value = "connect" onclick = "fnMain()">
</td>
</tr>
</table>
</div>
<div id=divResult>
</div>
</body>
</html>
Хотелось бы вместо тегов подключить какой-нить компонент вида GRID чтобы результат вываливался в него !!!
|
|
|