Solved

SQL Datasource Select Command

Posted on 2009-06-29
2
844 Views
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

            selectParameters.Add(spCustomer)

        Else

            spCustomer.Value = "%"

            selectParameters.Add(spCustomer)

        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

            selectParameters.Add(spStock)

        Else

            spStock.Value = "%"

            selectParameters.Add(spStock)

        End If
 

     

        For Each p As SqlParameter In selectParameters

            e.Command.Parameters.Add(p)

        Next
 

    End Sub

    Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)

        selectParameters.Clear()

    End Sub

Open in new window

0
Comment
Question by:directxBOB
2 Comments
 
LVL 22

Expert Comment

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

0
 
LVL 27

Accepted Solution

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

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now