Advertisement

04.09.2008 at 01:04AM PDT, ID: 23307381
[x]
Attachment Details

VB.NET, SqlDataSources & the SelectCommand Property

Asked by Lotok in Programming for ASP.NET, Visual Studio, .NET Framework 2.x

Tags:

Hi Folks.

I am hoping to gain some insight into why what I am trying does not work. Chances are it is a newbie coding error but there may be another reason.

I am creating an aspx page with a sqldatasource and a gridview. When a checkbox is checked, I want the SelectCommand property to change to a different SQl Query so that the gridview shows different information.

The current code does not throw an error but also shows no data. I am looking for ideas why. Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
VB CODE
 
 
 
    Public Property Query() As String
 
        Get
 
            Return _query
 
        End Get
 
        Set(ByVal value As String)
 
            _query = value
 
        End Set
 
    End Property
 
 
 
 
 
Protected Sub chk1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chk1.CheckedChanged
 
 
 
        If chk1.Checked = False Then
 
            Query() = "SELECT * FROM [Purchases] WHERE ([Dateordered] LIKE '%' + @Dateordered + '%') ORDER BY [Dateordered] DESC"
 
 
 
        Else
 
            Query() = "SELECT * FROM [Purchases] WHERE (([Dateordered] LIKE '%' + @Dateordered + '%') AND ([Datereceived] = '')) ORDER BY [Id] DESC"
 
 
 
        End If
 
    End Sub
 
 
 
 
 
 
 
 
 
 
 
SQL DataSource on ASPX Page
 
 
 
<asp:SqlDataSource ID="dsSQL1" runat="server" ConnectionString="<%$ ConnectionStringsbig grinSKBConnectionString1 %>" SelectCommand='<%# Query() %>'>
 
    <SelectParameters>
 
        <asp:ControlParameter ControlID="ddlmonths" DefaultValue="Jan" Name="Dateordered"
 
            PropertyName="SelectedValue" Type="String" />
 
    </SelectParameters>
 
</asp:SqlDataSource>
[+][-]04.09.2008 at 01:29AM PDT, ID: 21312830

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.09.2008 at 01:43AM PDT, ID: 21312877

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.09.2008 at 02:04AM PDT, ID: 21312968

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.09.2008 at 02:23AM PDT, ID: 21313039

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, Visual Studio, .NET Framework 2.x
Tags: VB.NET, ASP.NET
Sign Up Now!
Solution Provided By: Lotok
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628