Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
920
How to pass parameters to stored procedure in ObjectDataSource
posted

Hi

I have a project that generates three management charts from stored procedures using the UltraChart control.  I have followed the example in the online documentation "How to Create an Object Data Source Using Stored Procedures" however I have two questions

1. Is there a version of this code in VB.NET?

2. My stored procedures have two parameters @start_date and @end_date.  How do I pass these parameters to the ObjectDataSource?

Any help greatly appreciated.

Regards

James O'Doherty
Solution and Database Architect
Landesbank Berlin AG

 

Parents
  • 34510
    Offline posted

    Hi James,

    Here is the version of that code converted to VB.NET: 

    Public Function GetProducts() As IEnumerable(Of Product)
        Dim products As List(Of Product) = New List(Of Product)
    
        Using conn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("NORTHWIND").ConnectionString)
            conn.Open()
            Using cmd As New SqlCommand("ProductOrderedByPrice", conn)
                cmd.CommandType = System.Data.CommandType.StoredProcedure
                Using reader = cmd.ExecuteReader()
                    While reader.Read()
                        products.Add(New Product() With { _
                           .Code = CInt(reader("ProductID")), _
                           .Price = CDec(reader("UnitPrice")) _
                         })
                    End While
                End Using
            End Using
        End Using
    
        Return products
    End Function

     

    As for passing parameters to the stored procedures, the SqlCommand class has a Parameters collection with which you can add your parameters. http://msdn.microsoft.com/en-us/library/yy6y35y8%28v=vs.71%29.aspx

Reply Children
No Data