P
p byers
Hello Folks
Below is an extract from an Active Server Page that works OK
(apart from one thing that is !!!!)
It lists fields and info for a table in an Access database.
You will see that it cannot distinguish between 'Text'
and 'Memo'
(at the bottom of the script)
Two questions please.
a) How can I distinguish between 'Text' and 'Memo' ??
b) What is the full list of DataItems revealed by
'adSchemaColumns' ??
Could I have used a loop to reveal the name
and value for each item in rstMetaData ??
Thank you
Pete (Northolt UK)
*********************************************************************
*********************************************************************
Script is below
*********************************************************************
*********************************************************************
dataBaseRootSQL = "c:\inetpub\wwwroot\data\"
cBase = Request.QueryString("b")
cTable = Request.QueryString("t")
Response.Buffer = True
Const adSchemaColumns = 4
Const adSchemaTables = 20
Const adSchemaForeignKeys = 27
Const adSchemaPrimaryKeys = 28
' ADO Constants
Const adPersistXML = 1
Dim cnnSQL, rstMetaData, strSQL
Dim strConnection
Set cnnSQL = Server.CreateObject("ADODB.Connection")
Set rstMetaData = Server.CreateObject("ADODB.Recordset")
' Check that the connection was opened succesfully
'' strConnection = Request.QueryString("p")
''Response.Write (Request.QueryString("p") & "<P>xx<P>")
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
dataBaseRootSQL & "data\" & cBase
Response.Write ("<B>The Base is " & cBase & "</B><P>")
Response.Write ("<B>The Table is " & cTable & "</B><P>")
'' On Error Resume Next
cnnSQL.Open strConnection
If (Len(strConnection) = 0) Or (Err.Number <> 0) Then
Response.ContentType = "text/html"
Response.Write "There was an error with your connection string. Please
try again."
Response.End
End If
On Error GoTo 0
' ********** Get Columns **********
' Set criteria for adSchemaColumns; Get the list of columns from the
database
Set rstMetaData = cnnSQL.OpenSchema(adSchemaColumns)
Set rstMetaData = cnnSQL.OpenSchema(adSchemaColumns,Array(Empty, Empty,
"" & cTable & ""))
While Not rstMetaData.EOF
cThisField = rstMetaData("COLUMN_NAME")
cThisType = rstMetaData("DATA_TYPE")
cThisDesc = rstMetaData("DESCRIPTION")
if cThisType = 11 then
cType = "Logical (True/False or Yes/No)"
end if
if cThisType = 7 then
cType = "Date + Time"
end if
if cThisType = 130 then
cType = "String (Text or Memo)"
end if
if cThisType = 5 then
cType = "Number"
end if
if cThisType = 3 then
cType = "Auto Incrementing Number"
end if
'' Response.Write (cThisType & "^^^" & cThisField & "<BR>")
Response.Write ("<TR><TD>" & cThisField & "</TD><TD>" & cType &
"</TD><TD>" & cThisDesc & "</TD></TR>")
rstMetaData.MoveNext
Wend
Below is an extract from an Active Server Page that works OK
(apart from one thing that is !!!!)
It lists fields and info for a table in an Access database.
You will see that it cannot distinguish between 'Text'
and 'Memo'
(at the bottom of the script)
Two questions please.
a) How can I distinguish between 'Text' and 'Memo' ??
b) What is the full list of DataItems revealed by
'adSchemaColumns' ??
Could I have used a loop to reveal the name
and value for each item in rstMetaData ??
Thank you
Pete (Northolt UK)
*********************************************************************
*********************************************************************
Script is below
*********************************************************************
*********************************************************************
dataBaseRootSQL = "c:\inetpub\wwwroot\data\"
cBase = Request.QueryString("b")
cTable = Request.QueryString("t")
Response.Buffer = True
Const adSchemaColumns = 4
Const adSchemaTables = 20
Const adSchemaForeignKeys = 27
Const adSchemaPrimaryKeys = 28
' ADO Constants
Const adPersistXML = 1
Dim cnnSQL, rstMetaData, strSQL
Dim strConnection
Set cnnSQL = Server.CreateObject("ADODB.Connection")
Set rstMetaData = Server.CreateObject("ADODB.Recordset")
' Check that the connection was opened succesfully
'' strConnection = Request.QueryString("p")
''Response.Write (Request.QueryString("p") & "<P>xx<P>")
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
dataBaseRootSQL & "data\" & cBase
Response.Write ("<B>The Base is " & cBase & "</B><P>")
Response.Write ("<B>The Table is " & cTable & "</B><P>")
'' On Error Resume Next
cnnSQL.Open strConnection
If (Len(strConnection) = 0) Or (Err.Number <> 0) Then
Response.ContentType = "text/html"
Response.Write "There was an error with your connection string. Please
try again."
Response.End
End If
On Error GoTo 0
' ********** Get Columns **********
' Set criteria for adSchemaColumns; Get the list of columns from the
database
Set rstMetaData = cnnSQL.OpenSchema(adSchemaColumns)
Set rstMetaData = cnnSQL.OpenSchema(adSchemaColumns,Array(Empty, Empty,
"" & cTable & ""))
While Not rstMetaData.EOF
cThisField = rstMetaData("COLUMN_NAME")
cThisType = rstMetaData("DATA_TYPE")
cThisDesc = rstMetaData("DESCRIPTION")
if cThisType = 11 then
cType = "Logical (True/False or Yes/No)"
end if
if cThisType = 7 then
cType = "Date + Time"
end if
if cThisType = 130 then
cType = "String (Text or Memo)"
end if
if cThisType = 5 then
cType = "Number"
end if
if cThisType = 3 then
cType = "Auto Incrementing Number"
end if
'' Response.Write (cThisType & "^^^" & cThisField & "<BR>")
Response.Write ("<TR><TD>" & cThisField & "</TD><TD>" & cType &
"</TD><TD>" & cThisDesc & "</TD></TR>")
rstMetaData.MoveNext
Wend