use a string to define a sqldatasource parameter

Posted on 2006-05-05
Last Modified: 2008-02-01
I have created the following.
A sqldatasource using a parameter to retrieve data from the database which not older than todays date and display it in a gridview.

Below is the code :

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConn %>"
            SelectCommand="SELECT * FROM [calendar] WHERE ([appDate] > @appDate)">
                <asp:SessionParameter DefaultValue="01/06/2006" Name="appDate" SessionField="isToday"
                    Type="DateTime" />

On the code behind file I have created a DateTime variable called isToday
Dim isToday as DateTime =
and want to use this variable as below in the sqlDataSource Parameter.
<asp:SessionParameter DefaultValue="01/06/2006" Name="appDate" SessionField="isToday"

Should this work or am I doing this all wrong. I am very new to this so I would need all the code.
thanks vm

Question by:maxgall
    LVL 6

    Expert Comment

    You must save your date value in the browser session not as structure datetime:

    session("isToday") = Today

    Author Comment

    This is not excactly what I am looking for.
    Above I have the sqldatasource to retrieve data from my database. I now need to define a parameter to retrieve data which are
    > than todays date.

    In asp 1.0  I have just used a string and assigned the value   calendar1.todaysdate and passed this string on to the method to retrieve my data.  How can I do this now with the sqldatasource where the select command is as follows:
    SelectCommand="SELECT * FROM [calendar] WHERE ([appDate] > @appDate)">
    I used to be able to pass a string to the parameter @appDate.
    Is there something like:
    Dim myDate as String =
    <asp: StringParameter Name="appDate" String="myDate"

    LVL 6

    Accepted Solution

    Look at this sample, I hope it will help you:

    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <script runat="server">

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            SqlDataSource1.SelectParameters(0).DefaultValue = TextBox1.Text
        End Sub


    <html xmlns="" >
    <head runat="server">
        <title>Untitled Page</title>
        <form id="form1" runat="server">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
                    <asp:BoundField DataField="dummy" HeaderText="dummy" SortExpression="dummy" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dataConnectionString %>"
                SelectCommand="SELECT [dummy] FROM [dual] WHERE ([dummy] = @dummy)">
                    <asp:Parameter DefaultValue="" Name="dummy" Type="String" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Load" />

    Author Comment

    yes thanks that is working

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, 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 discusses moving either the default database or any database to a new volume.

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now