Jump to content

Show filtered results in cached table


13lack13lade
 Share

Recommended Posts

Hi All,

So i have a cached table and i have some text boxes to search and im a little stuck, i know how to set it up so that if your running the search vs a live sql connection against stored procedures however when it comes to cached tables im not sure how to do it.

Basically i have set it so the table will load and cache, then i want to make the applciation search that cached table so that the person can always search on the data weather or not there is a connection to the database (so always searching against the cached table)

There are only three search parameters which are two date fields (to give a date between) and 1 field is a 3 letter Code. the code i want to equal to whatever they say + '%' so that they do not need to enter it but they do need to enter the dates. 

How can i do this?

Front page image attached and this is the Current Code with attempted filtering:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;





namespace WebApplication5
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Cache["Data"] == null)
            {
                using (SqlConnection con = new SqlConnection("server=TOMSKEEZ-PC;database=MoneyBMine;integrated security=SSPI"))
                {
                    SqlDataAdapter da = new SqlDataAdapter("select * from NYSE_daily_price", con);
                    if (Cache["Data"] != null)
                    {
                        Cache.Remove("Data");
                    }
                    //set results to table
                    DataSet ds = new DataSet();
                    da.Fill(ds, "Data");
                    Cache.Insert("Data", ds);

                    GridView1.DataSource = ds;
                    GridView1.DataBind();
                    con.Close();
                }
            }
            else
            {
                DataSet ds = (DataSet)Cache["Data"];

                GridView1.DataSource = ds;
                GridView1.DataBind();

                if (Cache["Data"] == null)
                {
                    Label1.Text = "No data available, please wait until connection to database is available and try again.";
                }
                
            }
            
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            DataSet ds = (DataSet)Cache["Data"];
            DataRow[] foundRows;
            foundRows = ds.Tables["NYSE_daily_price"].Select("stock_symbol Like " + TxtStockSym.Text + "'%' and date between " + TxtDateFrom.Text + " and " + TxtDateTo.Text);
           GridView1.DataSource = foundRows;
           GridView1.DataBind();
                }
            }
        }

 

frontpage.jpg

Edited by 13lack13lade
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...