?
Solved

SQL Datasource Select Command

Posted on 2009-06-29
2
Medium Priority
?
850 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 total points
ID: 24737669
Is there an "AddWithValue" method?

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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 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