ASP做查询分析器(Query Analyzer)(V)
发表于:2007-06-30来源:作者:点击数:
标签:
DataTypeLib.asp % Function selectIdentity(strConnect,strTable,strColumn) Dim objConn, objRS, strFieldName, strFieldType, arrData, intRowCounter, intColCounter, strFieldValue Dim intUBoundRow, intUBoundCol, str SQL ID Set objConn=Server.Crea
DataTypeLib.asp
<%
Function selectIdentity(strConnect,strTable,strColumn)
Dim objConn, objRS, strFieldName, strFieldType, arrData, intRowCounter, intColCounter, strFieldValue
Dim intUBoundRow, intUBoundCol, str
SQLID
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = strConnect
objConn.Open
strSQLID = "SELECT COLUMNPROPERTY( OBJECT_ID(‘’"&strTable&"‘’),‘’"&strColumn&"‘’,‘’IsIdentity‘’)"
Set objRS = objConn.Execute(strSQLID)
If objRS.EOF and objRS.BOF then
Response.Write("No records matched or table is empty")
objRS.Close
Set objRS = Nothing
objconn.Close
Set objconn=Nothing
Else
‘’ Now lets grab all the records and close objects
arrData=objRS.Getrows
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
intUBoundRow = UBound(arrData,2)
intUBoundCol = UBound(arrData,1)
For intRowCounter = 0 to intUBoundRow
For intColCounter = 0 to intUBoundCol
strFieldValue = arrdata(intcolcounter,introwcounter)
If isNull(strFieldValue) then
strFieldValue ="<NULL>"
Elseif trim(strFieldValue)="" then
strFieldValue="<BLANK>"
End if
Next
Next
End if
selectIdentity = strFieldValue
End Function
Sub getIdentity(strServer, xdbname, xuserid, xpassword)
dim cnn, cat, tbl, fld, strCookieIdentity
dim connectstring
connectstring = _
"Provider=SQLOLEDB.1;Data Source="&strServer&";" & _
"Initial Catalog=" & xdbname & _
";UID=" & xuserid & ";PWD=" & xpassword & ";"
set cnn = server.createobject("adodb.connection")
set cat = server.createobject("adox.catalog")
set tbl = server.createobject("adox.table")
set fld = server.createobject("adox.column")
cnn.Open connectstring
cat.ActiveConnection = cnn
For Each tbl In cat.Tables
If tbl.Type = "TABLE" Then
For Each fld In tbl.columns
If selectIdentity(connectstring,tbl.name,fld.name) = 1 Then
strCookieIdentity = strCookieIdentity & tbl.name & fld.name
End If
Next
End If
Next
set cat = nothing
set tbl = nothing
cnn.Close
set cnn = nothing
response.cookies(xdbname & "strCookieIdentity") = strCookieIdentity & xdbname
end sub
Function getType(strFieldTypeNumber)
Dim strFieldType
Select Case strFieldTypeNumber
Case 0x2000
strFieldType = "adArray"
Case 20
strFieldType = "adBigInt"
Case 128
strFieldType = "adBinary"
Case 11
strFieldType = "adBoolean"
Case 8
strFieldType = "adBSTR"
Case 136
strFieldType = "adChapter"
Case 129
strFieldType = "adChar"
Case 6
strFieldType = "adCurrency"
Case 7
strFieldType = "adDate"
Case 133
strFieldType = "adDBDate"
Case 137
strFieldType = "adDBFileTime"
Case 134
strFieldType = "adDBTime"
Case 135
strFieldType = "adDBTimeStamp"
Case 14
strFieldType = "adDecimal"
Case 5
strFieldType = "adDouble"
Case 0
strFieldType = "adEmpty"
Case 10
strFieldType = "adError"
Case 64
strFieldType = "adFileTime"
Case 72
strFieldType = "adGUID"
Case 9
strFieldType = "adIDispatch"
Case 3
strFieldType = "adInteger"
Case 13
strFieldType = "adIUnknown"
Case 205
strFieldType = "adLongVarBinary"
Case 201
strFieldType = "adLongVarChar"
Case 203
strFieldType = "adLongVarWChar"
Case 131
strFieldType = "adNumeric"
Case 138
strFieldType = "adPropVari
ant"
Case 4
strFieldType = "adSingle"
Case 2
strFieldType = "adSmallInt"
Case 16
strFieldType = "adTinyInt"
Case 21
strFieldType = "adUnsignedBigInt"
Case 19
strFieldType = "adUnsignedInt"
Case 18
strFieldType = "adUnsignedSmallInt"
Case 17
strFieldType = "adUnsignedTinyInt"
Case 132
strFieldType = "adUserDefined"
Case 204
strFieldType = "adVarBinary"
Case 200
strFieldType = "adVarChar"
Case 12
strFieldType = "adVariant"
Case 139
strFieldType = "adVarNumeric"
Case 202
strFieldType = "adVarWChar"
Case 130
strFieldType = "adWChar"
Case Else
strFieldType = "Unknown Data Type"
End Select
getType = strFieldType
End Function
%>
原文转自:http://www.ltesting.net