PC Review


Reply
Thread Tools Rate Thread

ADO equivalent of dbQCrosstab?

 
 
pietlinden@hotmail.com
Guest
Posts: n/a
 
      24th Jan 2009
I'm wondering if I'm just missing something...

I am processing a collection of views/queries in a listbox (this part
is fine).

The problem is that I want to process Crosstabs in a different way
than I want to process normal Selects. In DAO, this is pretty
simple... just use DbEngine(0)(0).Querydefs("QueryName").Type to
determine what kind of query it is.

How do you do the same thing in ADO?
 
Reply With Quote
 
 
 
 
pietlinden@hotmail.com
Guest
Posts: n/a
 
      24th Jan 2009
On Jan 23, 6:54*pm, "pietlin...@hotmail.com" <pietlin...@hotmail.com>
wrote:
> I'm wondering if I'm just missing something...
>
> I am processing a collection of views/queries in a listbox (this part
> is fine).
>
> The problem is that I want to process Crosstabs in a different way
> than I want to process normal Selects. *In DAO, this is pretty
> simple... just use DbEngine(0)(0).Querydefs("QueryName").Type to
> determine what kind of query it is.
>
> How do you do the same thing in ADO?


I came up with this ugly workaround... it sort of works (I think...)
But I figured there would be an easier way... Maybe not...

But it's really awkward in ADO... in DAO, I can just loop through a
series of querydefs and just ask what type it is...

Select case qdf.Type
Case dbQSelect
'do one thing
Case dbQCrosstab
'do something else
Case Else
'do nothing
End Select

Public Function IsCrosstab(ByVal strViewName As String) As Boolean
On Error GoTo IsCrosstabError

Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim cmd As ADODB.Command


' Open the connection to the local database
Set cnn = CurrentProject.Connection
' Open the catalog
Set cat.ActiveConnection = CurrentProject.Connection

' point at the chosen object (if it exists)
Set cmd = cat.Procedures(strViewName).Command
IsCrosstab = Left$(cmd.CommandText, 9) = "TRANSFORM"
'retrieve field information

Set cmd = Nothing
Set cat = Nothing
cnn.Close
Set cnn = Nothing

Exit Function

IsCrosstabError:
' Debug.Print "Error Number: " & Err.Number & vbCrLf & "Text: &
err.Description"
IsCrosstab = False
Set cmd = Nothing
Set cat = Nothing
cnn.Close
Set cnn = Nothing
End Function
 
Reply With Quote
 
RoyVidar
Guest
Posts: n/a
 
      24th Jan 2009
(E-Mail Removed) wrote:
> On Jan 23, 6:54*pm, "pietlin...@hotmail.com" <pietlin...@hotmail.com>
> wrote:
>> I'm wondering if I'm just missing something...
>>
>> I am processing a collection of views/queries in a listbox (this
>> part is fine).
>>
>> The problem is that I want to process Crosstabs in a different way
>> than I want to process normal Selects. *In DAO, this is pretty
>> simple... just use DbEngine(0)(0).Querydefs("QueryName").Type to
>> determine what kind of query it is.
>>
>> How do you do the same thing in ADO?

>
> I came up with this ugly workaround... it sort of works (I think...)
> But I figured there would be an easier way... Maybe not...
>
> But it's really awkward in ADO... in DAO, I can just loop through a
> series of querydefs and just ask what type it is...
>
> Select case qdf.Type
> Case dbQSelect
> 'do one thing
> Case dbQCrosstab
> 'do something else
> Case Else
> 'do nothing
> End Select
>
> Public Function IsCrosstab(ByVal strViewName As String) As Boolean
> On Error GoTo IsCrosstabError
>
> Dim cnn As New ADODB.Connection
> Dim cat As New ADOX.Catalog
> Dim cmd As ADODB.Command
>
>
> ' Open the connection to the local database
> Set cnn = CurrentProject.Connection
> ' Open the catalog
> Set cat.ActiveConnection = CurrentProject.Connection
>
> ' point at the chosen object (if it exists)
> Set cmd = cat.Procedures(strViewName).Command
> IsCrosstab = Left$(cmd.CommandText, 9) = "TRANSFORM"
> 'retrieve field information
>
> Set cmd = Nothing
> Set cat = Nothing
> cnn.Close
> Set cnn = Nothing
>
> Exit Function
>
> IsCrosstabError:
> ' Debug.Print "Error Number: " & Err.Number & vbCrLf & "Text: &
> err.Description"
> IsCrosstab = False
> Set cmd = Nothing
> Set cat = Nothing
> cnn.Close
> Set cnn = Nothing
> End Function


You'd probably need

IsCrosstab = InStr(cmd.CommandText, "TRANSFORM") > 0

cause you may have parameters, which is defined at the "top of the
SQL".

You could probably also use the OpenSchema method, say (air code)

Public Function IsCrosstab(ByVal strViewName As String) As Boolean

Dim rs As ADODB.Recordset
Dim f As Boolean

f = False
Set rs = CurrentProject.Connection.OpenSchema( _
adSchemaProcedures, Array(Empty, Empty, strViewName))
If ((Not rs.Bof) And (Not rs.EOF)) Then
f = InStr(rs.Fields("PROCEDURE_DEFINITION").Value, _
"TRANSFORM") > 0
End If
IsCrosstab = f
rs.Close
Set rs = Nothing

End Function

But, why not use DAO?

--
Roy-Vidar


 
Reply With Quote
 
pietlinden@hotmail.com
Guest
Posts: n/a
 
      24th Jan 2009
On Jan 24, 3:03*am, RoyVidar <roy_vidarNOS...@yahoo.no> wrote:
> pietlin...@hotmail.com wrote:
> > On Jan 23, 6:54*pm, "pietlin...@hotmail.com" <pietlin...@hotmail.com>
> > wrote:
> >> I'm wondering if I'm just missing something...

>
> >> I am processing a collection of views/queries in a listbox (this
> >> part is fine).

>
> >> The problem is that I want to process Crosstabs in a different way
> >> than I want to process normal Selects. *In DAO, this is pretty
> >> simple... just use DbEngine(0)(0).Querydefs("QueryName").Type to
> >> determine what kind of query it is.

>
> >> How do you do the same thing in ADO?

>
> > I came up with this ugly workaround... it sort of works (I think...)
> > But I figured there would be an easier way... Maybe not...

>
> > But it's really awkward in ADO... in DAO, I can just loop through a
> > series of querydefs and just ask what type it is...

>
> > Select case qdf.Type
> > Case dbQSelect
> > * * 'do one thing
> > Case dbQCrosstab
> > * * 'do something else
> > Case Else
> > * * 'do nothing
> > End Select

>
> > Public Function IsCrosstab(ByVal strViewName As String) As Boolean
> > On Error GoTo IsCrosstabError

>
> > * * Dim cnn As New ADODB.Connection
> > * * Dim cat As New ADOX.Catalog
> > * * Dim cmd As ADODB.Command

>
> > * * ' *Open the connection to the local database
> > * * Set cnn = CurrentProject.Connection
> > * * ' * Open the catalog
> > * * Set cat.ActiveConnection = CurrentProject.Connection

>
> > * * ' * point at the chosen object (if it exists)
> > * * Set cmd = cat.Procedures(strViewName).Command
> > * * IsCrosstab = Left$(cmd.CommandText, 9) = "TRANSFORM"
> > * * 'retrieve field information

>
> > * * Set cmd = Nothing
> > * * Set cat = Nothing
> > * * cnn.Close
> > * * Set cnn = Nothing

>
> > Exit Function

>
> > IsCrosstabError:
> > ' * *Debug.Print "Error Number: " & Err.Number & vbCrLf & "Text: &
> > err.Description"
> > * * IsCrosstab = False
> > * * Set cmd = Nothing
> > * * Set cat = Nothing
> > * * cnn.Close
> > * * Set cnn = Nothing
> > End Function

>
> You'd probably need
>
> IsCrosstab = InStr(cmd.CommandText, "TRANSFORM") > 0
>
> cause you may have parameters, which is defined at the "top of the
> SQL".
>
> You could probably also use the OpenSchema method, say (air code)
>
> Public Function IsCrosstab(ByVal strViewName As String) As Boolean
>
> * * Dim rs * * * * * As ADODB.Recordset
> * * Dim f * * * * * *As Boolean
>
> * * f = False
> * * Set rs = CurrentProject.Connection.OpenSchema( _
> * * * * * *adSchemaProcedures, Array(Empty, Empty, strViewName))
> * * If ((Not rs.Bof) And (Not rs.EOF)) Then
> * * * * f = InStr(rs.Fields("PROCEDURE_DEFINITION").Value, _
> * * * * * * "TRANSFORM") > 0
> * * End If
> * * IsCrosstab = f
> * * rs.Close
> * * Set rs = Nothing
>
> End Function
>
> But, why not use DAO?
>
> --
> Roy-Vidar


I was looking for an alternative because I'm using ADO to convert
everything to delimited strings, which I can easily convert to tables
in Word. Maybe I should go the easy way, and write something to
convert the DAO recordset to a delimited string? Might just be going
about this ass backwards... Wouldn't be the first time, certainly, and
I doubt it will be the last.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net equivalent John Microsoft Access 2 20th Jan 2008 10:45 PM
FSO equivalent in VB.net =?Utf-8?B?QmVu?= Microsoft VB .NET 13 8th Dec 2006 09:04 PM
Equivalent of GetPrivateProfileString equivalent in C#? Germic Microsoft C# .NET 1 24th Jan 2005 09:22 AM
.NET ini equivalent guy Microsoft C# .NET 6 21st Oct 2004 09:09 AM
C++ equivalent in C# =?Utf-8?B?ZmFrdHVqYWE=?= Microsoft C# .NET 2 10th Mar 2004 07:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:27 AM.