Is it possible to work on dataset instead of database?

Last post 11-13-2009 2:01 AM by rush.svadi. 29 replies.

Sort Posts:

  • Is it possible to work on dataset instead of database?

    11-06-2009, 11:34 PM
    • Member
      125 point Member
    • rush.svadi
    • Member since 11-06-2009, 7:17 AM
    • Pune
    • Posts 88

    I have a gridview which shows the data from database after firing the search query. I want to implement mulple level filter with two dropdownlist over a gridview. So after returning the dataset from my first search query operation can i only play with the dataset to get further multiple searches instead of going back to database?

    If you want the complete scenario you can view the following post:

    http://forums.asp.net/t/1489776.aspx

    Thanks for yor help.

    Thanks and Regards,

    Rhishikesh.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 12:27 AM
    • Contributor
      3,278 point Contributor
    • Rajneesh Verma
    • Member since 07-15-2008, 10:22 AM
    • Lucknow, U.P. INDIA
    • Posts 745

    Hi,

    Instead of use dataset you should use datatable in which you can use search query.. check these links

    http://forums.asp.net/t/1426769.aspx

    http://forums.asp.net/t/1274083.aspx

    http://programming.top54u.com/post/ASP-Net-DataTable-Select-Function-to-Filter-Rows.aspx


    Thanks..

    RajneesH Verma
    Sr. Software Developer
    09839040266
    Technology Specialist at www.innovateonindia.com

    Please remember to click "Mark as Answer" on the post that helps you and close that thread which fulfill your requirement.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 12:28 AM

    you can push Search query result (dataset) in Cache,then for filtering as per selction Get it from cache -> Cast it to dataset and Fire "Select" method of datatable or you can use LINQ to dataset.


    thanks.



  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 1:15 AM





    see this example


    db script:

    create table Searching
    (
    FirstName varchar(100),
    LastName varchar(100)
    )
    insert into Searching
    select 'ram','reddy' union all
    select 'rami','abc' 

    create table Searching

    (

    FirstName varchar(100),

    LastName varchar(100)

    )

    insert into Searching

    select 'ram','reddy' union all

    select 'rami','abc' 



    <%@ Page Language="C#" AutoEventWireup="true"  %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>
                        Type : 
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlTypes" runat="server" AutoPostBack="true">
                            <asp:ListItem Value="1">FirstName</asp:ListItem>
                            <asp:ListItem Value="2">LastName</asp:ListItem>
                        </asp:DropDownList> 
                    </td>
                </tr>
                <tr>
                    <td>
                        Value : 
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlValues" runat="server" DataSourceID="sdColValues" 
                            DataTextField="val" DataValueField="val" AutoPostBack="True">
                        </asp:DropDownList> 
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:GridView ID="gvValues" runat="server" DataSourceID="sdValues">
                        </asp:GridView>
                        <asp:SqlDataSource ID="sdValues" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
                            SelectCommand="SELECT * FROM [Searching] WHERE 
                            case when @Type = 1 then FirstName when @Type =2 then LastName end
                             LIKE '%' + @Value + '%' ">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="ddlTypes" Name="Type" 
                                    PropertyName="SelectedValue" Type="String" />
                                <asp:ControlParameter ControlID="ddlValues" Name="Value" 
                                    PropertyName="SelectedValue" Type="String" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                        <asp:SqlDataSource ID="sdColValues" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
                            SelectCommand="SELECT distinct case when @Type =1 then FirstName when @Type = 2 then LastName end as val FROM [Searching] ">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="ddlTypes" Name="Type" 
                                    PropertyName="SelectedValue" Type="String" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>
    



    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 1:26 AM
    • Member
      313 point Member
    • cnranasinghe
    • Member since 10-27-2009, 12:41 AM
    • Sri Lanka
    • Posts 81

    For this type scenarios i use Developer Express aspxGridView (www.devexperience.com) . You can do nested 

    searches without writing a single line of code. Try It.



  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 1:31 AM

    Is that link working?? check it.........

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 1:42 AM
    • Contributor
      3,278 point Contributor
    • Rajneesh Verma
    • Member since 07-15-2008, 10:22 AM
    • Lucknow, U.P. INDIA
    • Posts 745

    Sorry, cnranasinghe

    Provided link does not work

    Output..

    This Domain is for Sale now! (buy now) Sorry to announce that this website is closed and decided to sell this domain displayed in URL window Contact us via pilyunk@yahoo.com Tel: +82.1075583648 Transaction will be done at Escrow.com Only for emergency contact dom2000101@hotmail.com Mobile phone:+82.1075583648 All Right Reserved by mySiteNames.com


    Check it ? 

    RajneesH Verma
    Sr. Software Developer
    09839040266
    Technology Specialist at www.innovateonindia.com

    Please remember to click "Mark as Answer" on the post that helps you and close that thread which fulfill your requirement.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 3:40 AM
    • Member
      125 point Member
    • rush.svadi
    • Member since 11-06-2009, 7:17 AM
    • Pune
    • Posts 88

    Thanks for replies guys......

    That devex.......... link is not working.... @ Ram -- Thanks for the post but that is not the actual sceatio i am working in.

    Rajneesh will u pls tell me if my select query returns multiple rows from datatable then how can i show it back to the grid? Is it possible?

    thanks.

     

    Thanks and Regards,

    Rhishikesh.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 3:44 AM
    • Member
      125 point Member
    • rush.svadi
    • Member since 11-06-2009, 7:17 AM
    • Pune
    • Posts 88

    Will you plaese explain me the code? thanks

    Thanks and Regards,

    Rhishikesh.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 4:28 AM
    • Contributor
      3,278 point Contributor
    • Rajneesh Verma
    • Member since 07-15-2008, 10:22 AM
    • Lucknow, U.P. INDIA
    • Posts 745

    Hi,

    rush.svadi:
    Rajneesh will u pls tell me if my select query returns multiple rows from datatable then how can i show it back to the grid? Is it possible?

    Yes use second custom datatable and fill that records to second datatable then bind to grid. or use same datatable count previous records store counting then insert record in than table and also delete previous record as you have counting.

    Just a logical scenario how can you achieve your goal.


    Thanks...

    RajneesH Verma
    Sr. Software Developer
    09839040266
    Technology Specialist at www.innovateonindia.com

    Please remember to click "Mark as Answer" on the post that helps you and close that thread which fulfill your requirement.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 4:46 AM
    • Member
      125 point Member
    • rush.svadi
    • Member since 11-06-2009, 7:17 AM
    • Pune
    • Posts 88

    Thanks rajneesh..... please eplain through the code. I am still quite confused as I am new to ASP.net.

    I am giving u my code here... 

     

    protected void ddldata_SelectedIndexChanged(object sender, EventArgs e)

    {

    DataRow[] ds ;

    string exp = "'" + ddlheaders.SelectedItem.ToString() + "' = '" + ddldata.SelectedItem.ToString() + "'";

    ds = _datatable.Select(exp);

    DataTable dtt = new DataTable();

    dtt.Rows.Add(ds);

    GridView1.DataSource = dtt;

    GridView1.DataBind();

    ddldata.Enabled = false;

    ddlheaders.Enabled = true;

    }

    where ddl header is dropdownlist of header row, ddldata is corresponding column data. _datatable is original datatable and dtt is newly created and gridview1 is is the grid.

    Thanks and Regards,

    Rhishikesh.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 4:49 AM

    rush.svadi:
    if my select query returns multiple rows from datatable then how can i show it back to the grid? Is it possible?


    use SqlDataAdapter Class Fill() method to call the query... It will returns a dataset or datatable. Then you can bind that datatable/dataset to gridview..

    SqlConnection myConn = new SqlConnection ( "your connection string" );

    SqlDataAdapter myAdapter = new SqlDataAdapter ( "your query", myConn );

    DataSet myData = new DataSet ( );

    myAdapter.Fill ( myData);

    Gridview1.DataSource = myData;

    Gridview1.DataBind();



    rush.svadi:
    but that is not the actual sceatio i am working in.

    From my understanding of the link that u specified in first post, I think its the scenario of 2 dropdownlists and a 1 gridview.

    2nd dropdownlist depends on 1st dropdownlist.. 

    and gridview depends on 2nd dropdownlist...

    I think the scenario i explained there is same.. the difference is i used sqldatasources(without writing code.) now by using sqldataadapter's fill() method u can do it without using sqldatasource controls....

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 4:56 AM
    • Member
      125 point Member
    • rush.svadi
    • Member since 11-06-2009, 7:17 AM
    • Pune
    • Posts 88

    thanks ram....... but here i am executing the select query on datatable. not on database. 

    and once that query is fired, it will return datarow[]. Now i have to bind this datarow[] to gridview. I dont know how this could be done.

    Thanks once again..... :)

    Thanks and Regards,

    Rhishikesh.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 5:02 AM

    yah.. u can still bind that datarow array to gridview..

    DataRow[] dr = // your some operation;

    Gridview1.DataSource = dr;

    Gridview1.DataBind();

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: Is it possible to work on dataset instead of database?

    11-07-2009, 5:13 AM
    • Member
      125 point Member
    • rush.svadi
    • Member since 11-06-2009, 7:17 AM
    • Pune
    • Posts 88

    Ram.. thanks

    But thats not working becoz the query returns multiple rows. I am getting a page with no gridview at all.

    I want to like this(I am not sure whether my logic is correct). for reference please have look at above code.

    1. Retrieve a DataTable _datatable from database.

    2. Fire a select query to _datatable to return DataRow[] ds. here i may get multiple rows.

    3. Convert DataRow[] to DataTable dtt.

    4 And bind dtt to gridview1.

    Hope u understand what am i actually trying to do.........Thanks.....

    Thanks and Regards,

    Rhishikesh.
Page 1 of 2 (30 items) 1 2 Next >