Saturday, March 3, 2018

Run query on dataset

if you want to query on dataset you can simply do this no need to again hit database:

-- storing in Dataset
  Dim ds As New DataSet
    Dim ds_1 As New DataSet
   ds = getData()
   Session("ds_data") = ds


 -- Retrieving from Dataset
      Dim foundRows() As DataRow
       ds_1 = DirectCast(Session("ds_data"), DataSet) ' get data from session data
foundRows = ds.Tables(0).Select("table_ID = '" + hdn_ID.Value + "' ") ' table_ID is my column name
dim user_name as String =foundRows(0)("Customer Name")

-- Another Option
One more you can do you can make a new data-set and copy that filter data in to new data-set

Dim ds_Stats As DataSet
Dim ds_StatsAddress As DataSet
Dim ds_StatsPic As DataSet
ds_Stats = oApproveaddress.getData()
            ds_StatsPic = New DataSet()
            ds_StatsPic.Merge(ds_Stats.Tables(0).Select("id = '3' "))
            ds_StatsAddress = New DataSet()
            ds_StatsAddress.Merge(ds_Stats.Tables(0).Select("id = '4' "))


If ds_Stats.Tables(0).Select("documentid = '3' ").Length > 0 Then
                RepeaterPic.DataSource = ds_StatsPic.Tables(0)
                RepeaterPic.DataBind()
            Else
                RepeaterPic.DataSource = Nothing
                RepeaterPic.DataBind()
            End If


            If ds_Stats.Tables(0).Select("documentid = '4' ").Length > 0 Then
                RepeaterAddress.DataSource = ds_StatsAddress.Tables(0)
                RepeaterAddress.DataBind()
            Else
                RepeaterAddress.DataSource = Nothing
                RepeaterAddress.DataBind()
            End If

-- Sorting in Dataset

  Dim ds_Re As DataSet
        ds_Re= New DataSet()
        ds_Re.Merge(ds.Tables(0).Select("", "Date DESC"))
        If ds.Tables(0).Select("Is_Recommended = True ").Length > 0 Then
            rptReco.DataSource = ds_Recommended.Tables(0)
            rptReco.DataBind()

        End If

Refer

No comments:

Post a Comment