locked
How to use VisualWeb/VS 2010 to add Query into Access mdb file ? RRS feed

  • Question

  • User-775831949 posted

    I have a mdb file and using Visual Web/VS2010

    I need to create a new query in mdb file.

    So I use VW2010 database Explorer to browse my mdb

    It shows Table1 properly with fields ID, Country, Sales.

    I need to add a query in this mdb Select Country, Sales from Table1.

    So I right click View folder, Select "New Query"

    Then in db diagram and check the boxes vs Country and Sales. SQL is good.

    So far no problem up till now.

    However, there is no way for me to save this query into mdb. Even I click Save all button, there is no new VIEW/query added to mdb file.

    Anyone knows what I should do ? Thanks

    Wednesday, November 19, 2014 11:40 PM

Answers

  • User-821857111 posted

    Visual Studio doesn't provide the tools for creating saved queries in mdb files. You can either open the file with Access and create the saved query, or you can use Data Definition Language (DDL) from code to create a saved query:

    Dim ddl = "CREATE PROCEDURE GetSales AS SELECT Country, Sales FROM Table1"
    Using conn As New OleDbConnection(yourConnectionString)
        Using cmd As New OleDbCommand(ddl, conn)
            conn.Open()
            cmd.ExecuteNonQuery()
        End Using
    End Using



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2014 3:25 AM