views:

91

answers:

2

Microsoft Access queries with somecolumnname = [?] do not show up in the list of Views in the New DataSource Wizard in Visual Studio.

The query works perfectly from within Microsoft Access by just prompting for the values of the parameters.

The columns of the query should populate labels on my form based on the values in a couple textboxes.

What is the "best-practices" way to use parameter queries in my .NET application?

Note: If applicable, VB.NET answers preferred over C# (both acceptable).

A: 

What if you do this:

somecolumnname = ?

instead of

somecolumnname = [?]

Take a look at this:

Paremeters in TableAdapter not accepted

Are you missing some step?

How to: Connect to Data in an Access Database

Walkthrough: Connecting to Data in an Access Database (Windows Forms)

Leniel Macaferi
That won't help.
SLaks
He's trying to access a saved Access query. It may be exposed as a sproc.
SLaks
Is it possible to have a valid saved Access QueryDef with "omecolumnname = ?" in it? Given that "?" is the standard Jet/ACE SQL single-character wildcard (like _ in SQL Server), I don't think it will work.
David-W-Fenton
I don't know anything about .NET, but an Access parameter query is more like an SPROC than it is like a VIEW. It should not be surprising if they did not show up in a list of VIEWs.
David-W-Fenton
Your answer directly didn't help. However, your links pointed me in the right direction. I just removed the `somecolumnname = ?` from the query in access, added a query to the `TableAdapter`, then added the condition to the newly created `TableAdapter.FillBy` query.
Steven
Good to know the links helped you.
Leniel Macaferi
A: 

This is based on a little understanding of Access, not of VB.Net, but it may help.

    Dim cn As New OleDb.OleDbConnection
    Dim cmd As New OleDb.OleDbCommand

    Try
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
       "Data Source=c:\Docs\Test.mdb;"
        cn.Open()

        cmd.Connection = cn
        ''It is just a query, not a procedure, but this is what
        ''works with Access
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "test"
        With cmd.Parameters
            .AddWithValue("myparam", "SomeVal")
        End With

     <...>

OLE DB Providers: http://www.carlprothman.net/Default.aspx?tabid=87#OLEDBProviderForMicrosoftJet

Remou