Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

VB.NET/MS Access sql problem

  • 12-08-2011 10:43am
    #1
    Registered Users, Registered Users 2 Posts: 2,598 ✭✭✭


    Having a bit of bother filling a DataSet.
    Background ... VB.NET application, MS Access database

    I want to concatenate 2 of the fields in a query so the SQL and have them seperated by a hyphen as so:

    SELECT [Field1] & " - " & [Field2] AS [JoinedFields],
    SUM([Field3]) AS [TotalField3]
    GROUP BY Field1, Field2


    When I run this directly in the MS Access query it works fine, results shown as :

    [JoinedFields] ... [TotalField3]
    [AAA - BBBBB] ........... [ 2 ]
    [AAA - CCCCC] ........... [ 5 ]
    [AAA - DDDDD] ........... [ 2 ]
    [BBB- AAAAAA] ........... [ 1 ]
    [BBB - BBBBB ] ........... [ 3 ]
    [BBB - DDDDD] ........... [ 7 ]

    Problem is when I run it through VB.NET to fill a DataSet

    Dim DBCommand = New OdbcCommand(sSQL, DBConnection)
    daQueryResults.SelectCommand = DBCommand
    daQueryResults.Fill(dsQueryResults, "QueryResultsDataSet")


    On the Fill I get :
    "ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1."

    Any idea what I'm doing wong?


Comments

  • Registered Users, Registered Users 2 Posts: 1,456 ✭✭✭FSL


    Why have you got quotation marks around QueryResultsDataSet?

    Presumably QueryResultsDataSet is a variable by putting quotation marks around it you are sending the string "QueryResultsDataSet" not the contents of QueryResultsDataSet.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Can you post the complete code listing? It's difficult to understand what exactly your doing with only 3 lines of actual code.


  • Registered Users, Registered Users 2 Posts: 2,598 ✭✭✭Saint_Mel


    Evil Phil wrote: »
    Can you post the complete code listing? It's difficult to understand what exactly your doing with only 3 lines of actual code.

    Yep,

    Dim sConnectionString As String = "dsn=myConnectionString"
    Dim DBConnection As New Odbc.OdbcConnection(sConnectionString)
    Dim daQueryResults As New OdbcDataAdapter
    Dim dsQueryResults As New DataSet

    Try

    Dim sSQL As String = ""
    sSQL = "SELECT [Field1] & " & """ - """ & " & [Field2] AS [JoinedFields], SUM([Field3]) AS [TotalField3] FROM myTable GROUP BY Field1,Field2"

    Dim DBCommand = New OdbcCommand(sSQL, DBConnection)
    daQueryResults.SelectCommand = DBCommand
    daQueryResults.Fill(dsQueryResults, "QueryResultDataSet")

    Catch exODBC As Data.Odbc.OdbcException
    ...
    ...
    ...


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Try apostrophes instead of quote in you SQL string
    sSQL = "SELECT [Field1] & ' - ' & [Field2] AS [JoinedFields], SUM([Field3]) AS [TotalField3] FROM myTable GROUP BY Field1,Field2"
    

    It's been a while, but from what I remember the .Net Access adapter is a little less flexible with the characters it supports than Access itself, often leading to cryptic errors like this one.


  • Registered Users, Registered Users 2 Posts: 2,598 ✭✭✭Saint_Mel


    stevenmu wrote: »
    Try apostrophes instead of quote in you SQL string
    sSQL = "SELECT [Field1] & ' - ' & [Field2] AS [JoinedFields], SUM([Field3]) AS [TotalField3] FROM myTable GROUP BY Field1,Field2"
    

    It's been a while, but from what I remember the .Net Access adapter is a little less flexible with the characters it supports than Access itself, often leading to cryptic errors like this one.

    Fantastic, that worked perfect. Thanks a million for your help


  • Advertisement
Advertisement