Tech Off Thread

18 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

DataView Object

Back to Forum: Tech Off
  • User profile image
    r_taduri

    Hi Friends,

       How to retireve modifed rows after using filter condition in a datatable object.

    ex:

    Below is the code writeen in Custom Datagrid's OnDataBIndinding event:

    dim dv as dataview
    dv=mybase.datasource  
    dim tempdt as datatable=dv.table

    By using dv.table, I am getting all the rows, but I want to get only filtered rows.

    Let me know your comments.

    Thanks in advance.

    Regards,

    Subbarao

  • User profile image
    blowdart

    r_taduri wrote:
    Hi Friends,
    dim dv as dataview
    dv=mybase.datasource  
    dim tempdt as datatable=dv.table

    By using dv.table, I am getting all the rows, but I want to get only filtered rows.



    You don't need to go into the table, simply bind to the view once you have set a suitable filter. The gotdotnet site has a good sample.

  • User profile image
    r_taduri

    Thanks,

      I need to retrieve those filtered rows from a dataview object into a datatable objects.

    Help me

    Regards,

    Subbarao

  • User profile image
    blowdart

    r_taduri wrote:
    Thanks,

      I need to retrieve those filtered rows from a dataview object into a datatable objects.



    OK, might I ask why? You can certainly databind against a view.

    If you feel you must you could clone the internal datatable to get the schema;

    DataTable newDt = dataViewObject.Table.Clone();

    then enumerate over the rows in the view appending them to the new data table.


  • User profile image
    TommyCarlier

    Or you could use the ToTable()-method.

  • User profile image
    blowdart

    TommyCarlier wrote:
    Or you could use the ToTable()-method.


    Which unfortunately is .net 2.0 only. But yes, I obviously need more coffee Smiley

  • User profile image
    r_taduri

    Thanks.

      I already try your approach. But there are som custom columns also. If I clear table's data and enumerate then I got problems regarding custom columns.

    After binding data to datagird, there are options for Add, Remove and Filter .

    If I use Add and Remove without apply Filter condition then it works fine.

    If I filter data based on some condition and apply "Remove" for particular column(template column with checkbox) then I got problem since another row is removed irrespective of checked row.

    Here I am placing CustomDatagrid's OnDataBinding events code

                MyBase.PageSize = rowsddl.SelectedValue
                Dim dv As DataView
                dv = MyBase.DataSource
                Dim tempDt As DataTable = dv.Table
                If _removeColumn Then
                    If Not tempDt.Columns.Contains("Remove") Then
                        Dim col As DataColumn = New DataColumn("Remove",

    GetType(Boolean))
                        col.ReadOnly = False
                        col.DefaultValue = False
                        tempDt.Columns.Add(col)
                        dv = tempDt.DefaultView
                    End If
                End If

                ' add columns into datagrid if showAllColumns is True and is not

    called in Onload yet
                'If _showAllColumns AndAlso IsNothing(Me.Page.Session(Me.ID)) Then

    AddDatagridColumns(tempDt)
                If _showAllColumns Then AddDatagridColumns(tempDt)

                Dim iCount = dv.Count()
                If iCount = 0 Then
                    isNoRecord = True
                Else
                    isNoRecord = False
                    If (MyBase.PageSize = rowsddl.Items(0).Value And iCount <=

    MyBase.PageSize) Then
                        MyBase.AllowPaging = False
                    Else
                        MyBase.AllowPaging = True
                    End If
                End If

                MyBase.OnDataBinding(e)

                Me.Page.Session(Me.ID) = dv.Table
                Me.ViewState("isNoRecord") = isNoRecord
                dv = Nothing
    -----------------------------------------------------------------------------------
     I observe that

    dv.count is not matched with tempdt.rows.count

    I am also place folllowing code to get id for removing particular row

            Private Function GetRemoveList() As String
                Dim resultStr As String = ""
                Dim drs As DataRow()
                Dim dr As DataRow
                Dim tempDt As DataTable = Me.Page.Session(Me.ID)
                drs = tempDt.Select("Remove=True")
                For Each dr In drs
                    resultStr = resultStr & CStr(dr(0)) & ","
                Next dr
                If resultStr <> "" Then resultStr = Left(resultStr, resultStr.Length - 1)
                GetRemoveList = resultStr
            End Function
    ----------------------------------------

    Here resultStr is not matched with What I checked in my page.

    Regards,

    Subbarao

  • User profile image
    blowdart

     I observe that

    dv.count is not matched with tempdt.rows.count


    Well no it won't be if you have filters.

    Is there a particular reason you must bind to a table, and not a view created over it?

  • User profile image
    r_taduri

    This is Custom Datagrid, all of the pages, the data  binded to Dataview object, neither a dataset nor a datatable object.



  • User profile image
    blowdart

    r_taduri wrote:
    This is Custom Datagrid, all of the pages, the data  binded to Dataview object, neither a dataset nor a datatable object.


    OK and delete doesn't work? It just deletes everything you are currently filtering on?

  • User profile image
    r_taduri

    After filter and apply remove then another record is deleted instead of my chosen record

  • User profile image
    blowdart

    r_taduri wrote:
    After filter and apply remove then another record is deleted instead of my chosen record


    Oh I see, almost like it's deleting by record number, rather than a primary key?

    For example I have a dataset say that has 1,2,3,4,5 in it, I apply a filter which excludes 4, so the dataview has 1,2,3,5 in it and then when I try to delete 5 what happens is that 4 vanishes?

  • User profile image
    r_taduri

    absolutely, i neet to fetch correct one

  • User profile image
    blowdart

    r_taduri wrote:
    absolutely, i neet to fetch correct one


    Ah I see, and this is the delete code?

                Dim resultStr As String = ""
                Dim drs As DataRow()
                Dim dr As DataRow
                Dim tempDt As DataTable = Me.Page.Session(Me.ID)
                drs = tempDt.Select("Remove=True")
                For Each dr In drs
                    resultStr = resultStr & CStr(dr(0)) & ","
                Next dr
                If resultStr <> "" Then resultStr = Left(resultStr, resultStr.Length - 1)
                GetRemoveList = resultStr

    But it's going through the table, not the view ....

  • User profile image
    r_taduri

    I need to delete the correct one, but the following code does't fetch the correct one.

    Private Function GetRemoveList() As String
                Dim resultStr As String = ""
                Dim drs As DataRow()
                Dim dr As DataRow
                Dim tempDt As DataTable = Me.Page.Session(Me.ID)
                drs = tempDt.Select("Remove=True")---> this is template column
                For Each dr In drs
                    resultStr = resultStr & CStr(dr(0)) & ","
                Next dr
                If resultStr <> "" Then resultStr = Left(resultStr, resultStr.Length - 1)
                GetRemoveList = resultStr
            End Function
    the resultStr is not getting correct one.

  • User profile image
    blowdart

    I guess I am not getting this correctly Smiley

    Is there any way you can zip up that page, and something in the Session_OnStart that creates a suitable dataset so we can download it and poke about?

  • User profile image
    r_taduri

    give me your mail id

  • User profile image
    blowdart

    r_taduri wrote:
    give me your mail id


    barryd at idunno dot org.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.