开发者

Access Query With Parameters in Visual Studio

Microsoft Access queries with somecolumnname = [?] do not show up in the list of Views in the New开发者_Python百科 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).


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜