Link to home
Start Free TrialLog in
Avatar of Sheritlw
SheritlwFlag for United States of America

asked on

Send Parameters to Stored Query

I have a VB 2008 app with an access backend.
Within this access db, I have a large table.  
I have made a stored query for this table to handle inserts and updates,  now I need to  know how to I reference this stored query and send in the parameters from the VB 2008 app.
Please provide sample code and no links.  My IE crashes when I click on links.
Thank you
Avatar of aboredman
aboredman

This is for a SQL server stored proc but it's pretty much the same for access...

Imports System
Imports System.Data
Imports System.Data.SqlClient

Class MainClass
    Public Shared Sub Main()
        Using con As New SqlConnection()
            con.ConnectionString = "Data Source = .\sqlexpress;Database = Northwind; Integrated Security=SSPI"
            con.Open()
           
            Dim category As String = "Seafood"
            Dim year As String = "1999"
           
            ' Create and configure a new command.
            Using com As SqlCommand = con.CreateCommand()
                com.CommandType = CommandType.StoredProcedure
                com.CommandText = "SalesByCategory"
               
                ' Create a SqlParameter object for the category parameter.
                com.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value = category
               
                ' Create a SqlParameter object for the year parameter.
                com.Parameters.Add("@OrdYear", SqlDbType.NVarChar).Value = year
               
                ' Execute the command and process the results.
                Using reader As IDataReader = com.ExecuteReader()
                    Console.WriteLine("Sales By Category ({0}).", year)
                   
                    While reader.Read()
                        ' Display the product details.
                        Console.WriteLine("  {0} = {1}", reader("ProductName"), reader("TotalPurchase"))
                    End While
                End Using
               
            End Using
        End Using
    End Sub
End Class


***My IE crashes when I click on links***... you might want to use firefox...

Avatar of Sheritlw

ASKER

I appreciate the example, but I've tried to convert to MS Access and they fail.
I really need an example for Access.
Thanks
ASKER CERTIFIED SOLUTION
Avatar of aboredman
aboredman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial