How to modify dataset data?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vertigo262
    New Member
    • Jul 2007
    • 62

    How to modify dataset data?

    Is this possible?

    I'm trying to call a dataset, modify a value, and then put it back into a dataset.
    I think this is possible but I'm doing something wrong

    Any help would be greatly appreciated

    attached is an image of the table and the code

    Code:
     Public Function GetSideBannersDir() As DataSet
    
            Dim Conn As New SqlConnection(ConnectionString)
            Dim CmdSelect As New SqlCommand("GetSideBanners", Conn)
            CmdSelect.CommandType = CommandType.StoredProcedure
    
            Dim Da As New SqlDataAdapter(CmdSelect)
            Dim Ds As New DataSet
    
            'Fill the Dataset
            Try
                Da.Fill(Ds)
    
                Dim FormatImageURL As String = Ds.Tables("Banners").Rows(0)("ImageUrlField")
                Ds.Tables("Banners").Rows(0)("ImageUrlField") = "/Data" & FormatImageURL
    
    
                Context.Response.Write("<br><br>DB" & Ds.Tables(3).Rows(0)("ImageUrlField"))
                'Context.Response.End()
                Da.Fill(Ds, "Banners")
    
                Return Ds
    
    
    
            Catch ex As Exception
                'Throw New ApplicationException("Data Error")
            Finally
                Conn.Close()
            End Try
    
        End Function
    Attached Files
  • vertigo262
    New Member
    • Jul 2007
    • 62

    #2
    thinking would be more like this.
    need to loop through the table rows

    Code:
    Public Function GetSideBannersDir() As DataSet
    
            Dim Conn As New SqlConnection(ConnectionString)
            Dim CmdSelect As New SqlCommand("GetSideBanners", Conn)
            CmdSelect.CommandType = CommandType.StoredProcedure
    
            Dim Da As New SqlDataAdapter(CmdSelect)
            Dim Ds As New DataSet
    
            'Fill the Dataset
            Try
                Da.Fill(Ds)
    
                Dim i As Integer
                Dim rowcount As Integer = Ds.Tables(0).Rows.Count
                For i = 0 To rowcount - 1
                    Dim FormatImageURL As String = Ds.Tables("Banners").Rows(i)("ImageUrlField")
                    Ds.Tables("Banners").Rows(i)("ImageUrlField") = "/Data" & FormatImageURL
    
                    Context.Response.Write("<br><br>DB" & Ds.Tables("Banners").Rows(i)("ImageUrlField"))
                Next i
    
    
                'Context.Response.End()
                Da.Update(Ds)
    
                Return Ds
    
    
    
            Catch ex As Exception
                Throw New ApplicationException("Data Error")
            Finally
                Conn.Close()
            End Try
    
        End Function

    Comment

    • vertigo262
      New Member
      • Jul 2007
      • 62

      #3
      OK, this is cleaner, but still not working
      Sigh

      Code:
       Public Function GetSideBannersDir() As DataSet
      
              Dim Conn As New SqlConnection(ConnectionString)
              Dim CmdSelect As New SqlCommand("GetSideBanners", Conn)
              CmdSelect.CommandType = CommandType.StoredProcedure
      
              Dim Da As New SqlDataAdapter(CmdSelect)
              Dim Ds As New DataSet
      
              'Fill the Dataset
              Try
                  Da.Fill(Ds)
      
                  For Each dr As DataRow In Ds.Tables("Banners").Rows
      
                      Dim FormatImageURL As String = ("ImageUrlField")
                      dr("ImageUrlField") = "/Data" & FormatImageURL
      
                  Next
      
                  Da.Update(Ds)
      
                  Return Ds
      
      
      
              Catch ex As Exception
                  'Throw New ApplicationException("Data Error")
              Finally
                  Conn.Close()
              End Try
      
          End Function

      Comment

      • vertigo262
        New Member
        • Jul 2007
        • 62

        #4
        So confused,

        Here is the recent code. everything is working, after the loop, it response writes the correct data.

        but it's either not updating the dataset, or it's empty because when I call the dataset from a page, no data populates.


        Code:
        Public Function GetSideBannersDir() As DataSet
        
                Dim Conn As New SqlConnection(ConnectionString)
                Dim CmdSelect As New SqlCommand("GetSideBanners", Conn)
                CmdSelect.CommandType = CommandType.StoredProcedure
        
                Dim Da As New SqlDataAdapter(CmdSelect)
                Dim Ds As New DataSet
        
                'Fill the Dataset
                Try
                    Da.Fill(Ds, "Banners")
        
                    For Each dr As DataRow In Ds.Tables("Banners").Rows
        
                        Dim FormatImageURL As String = dr("ImageUrlField")
                        dr("ImageUrlField") = "/" + Context.Application("SysDataDir") & FormatImageURL
        
                        Context.Response.Write("loop: " & dr("ImageUrlField"))
        
                    Next
        
                    Da.Update(Ds, "Banners")
        
                    Return Ds
        
        
        
                Catch ex As Exception
                    'Throw New ApplicationException("Data Error")
                Finally
                    Conn.Close()
                End Try
        
            End Function

        Comment

        Working...