HomeActive Query BuilderGet Parameters List from Query using Query Analyzer in Non-Visual Mode

Get Parameters List from Query using Query Analyzer in Non-Visual Mode


Hi,

I want to retrieve the list of parameter names from a query when the database connection or schema is not available. I don't need the parameter db type and other information, just query names. Is that possible?

Best Regards.
Salman Khalid.
Sr. Software Developer.
www.premierpos.com
Salman Khalid | email
December 3 2008, 12:11 AM
Dear Salman,

You don't have to connect to the database or even set the metadata provider to retrieve parameters, but the syntax provider is necessary for this operation. The following code works fine without database connection:

for (int i = 0; i < queryBuilder1.Parameters.Count; i++)
{
String paramName = queryBuilder1.Parameters[i].FullName;
}
Sergey Smagin | email
45 mins since original post
Thanks for the prompt reply... actually i already tried that, but didn't work for me. Below is a code snippet that i used... which always gives Parameters collection to be NULL. Am i missing something?

Dim query As String = "Select * from TABLENAME Where columnName = @Col AND col2 = @cooool2"
Dim q As New ActiveDatabaseSoftware.ActiveQueryBuilder.QueryBuilder(True)
q.SyntaxProvider = New ActiveDatabaseSoftware.ActiveQueryBuilder.MSSQLSyntaxProvider

q.SyncSQL = query

If q.Parameters Is Nothing Then
MessageBox.Show("No Params")
Else
MessageBox.Show(q.Parameters.Count.ToString())
End If
Salman Khalid | email
50 mins since original post
Try to use "q.Parameters.Count = 0" instead of "q.Parameters Is Nothing".
I tested your query without database connection; parameters were found.
Sergey Smagin | email
11 hours, 39 mins since original post
I used q.Parameters Is Nothing 'cos if i use 'If q.Parameters.Count = 0 Then' instead, i get the 'Object reference not set to an instance of an object' error. (i.e. Parameter collection is not initialized.

Is there some method or something i need to do for it to analyze the query and create the Parameter collection? Did you try running the code as i pasted above?

Best regards.
Salman Khalid.
Salman Khalid | email
12 hours, 32 mins since original post
Insert following string after the "q.SyncSQL = query" line:

Dim dummy As String = q.SQL;

It will initialize the parameters.
Eugene Starkov | email
23 hours, 31 mins since original post
Eugene,

Thank you! That worked like a charm. :)

Best Regards.
Salman Khalid.
Salman Khalid | email
23 hours, 37 mins since original post
This topic is closed