SQL Datasource Select Command

Posted on 2009-06-29
Medium Priority
Last Modified: 2013-12-17
I have a select command which has 2 parameters

select * from Products where id like @Customer and inStock = @inStock

So what I am doing is putting parameters using the Selecting Event. The problem I am having is that the parameters don't seem to be taking effect.

Any ideas as to what might be wrong? This works fine when doing an insert, and was hoping to use this for the a select so I could automatically filter the Gridview, without ruiing my Update, Insert, Cancel that I have going on with the gridview.

Private selectParameters As New List(Of SqlParameter)()
Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)
        Dim spCustomer As New SqlParameter("@Customer", SqlDbType.VarChar, 255)
        spCustomer.Direction = ParameterDirection.Input
        If Not ddlCustomers.SelectedValue.Equals("-1") Then
            'gridviewSelect = gridviewSelect + " and ProductWholesaler ='" + ddlCustomers.SelectedValue + "'"
            spCustomer.Value = ddlCustomers.SelectedValue
            spCustomer.Value = "%"
        End If
        Dim spStock As New SqlParameter("@Stock", SqlDbType.VarChar, 255)
        spStock.Direction = ParameterDirection.Input
        If Not ddlStock.SelectedValue.Equals("-1") Then
            'gridviewSelect = gridviewSelect + " and ProductStock ='" + ddlStock.SelectedValue + "'"
            spStock.Value = ddlStock.SelectedValue
            spStock.Value = "%"
        End If
        For Each p As SqlParameter In selectParameters
    End Sub
    Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
    End Sub

Open in new window

Question by:directxBOB
LVL 22

Expert Comment

ID: 24737373
>>>The problem I am having is that the parameters don't seem to be taking effect.
No data returned?

LVL 27

Accepted Solution

VBRocks earned 2000 total points
ID: 24737669
Is there an "AddWithValue" method?

    selectParameters.AddWithValue("@Customer", ddlStock.SelectedValue)

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
The PowerShell Core 6.0 of .NET release is just the beginning. The upcoming PowerShell Core 6.1 would have artificial intelligence and internet of things capabilities. So many things to look forward to in the upcoming release.
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…
Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question