directxBOB
asked on
SQL Datasource Select Command
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.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No data returned?