473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Expand|Select|Wrap|Line Numbers
  1.  Public Function GetSideBannersDir() As DataSet
  2.  
  3.         Dim Conn As New SqlConnection(ConnectionString)
  4.         Dim CmdSelect As New SqlCommand("GetSideBanners", Conn)
  5.         CmdSelect.CommandType = CommandType.StoredProcedure
  6.  
  7.         Dim Da As New SqlDataAdapter(CmdSelect)
  8.         Dim Ds As New DataSet
  9.  
  10.         'Fill the Dataset
  11.         Try
  12.             Da.Fill(Ds)
  13.  
  14.             Dim FormatImageURL As String = Ds.Tables("Banners").Rows(0)("ImageUrlField")
  15.             Ds.Tables("Banners").Rows(0)("ImageUrlField") = "/Data" & FormatImageURL
  16.  
  17.  
  18.             Context.Response.Write("<br><br>DB" & Ds.Tables(3).Rows(0)("ImageUrlField"))
  19.             'Context.Response.End()
  20.             Da.Fill(Ds, "Banners")
  21.  
  22.             Return Ds
  23.  
  24.  
  25.  
  26.         Catch ex As Exception
  27.             'Throw New ApplicationException("Data Error")
  28.         Finally
  29.             Conn.Close()
  30.         End Try
  31.  
  32.     End Function
  33.  
Attached Images
File Type: jpg BannersTable.jpg (81.4 KB, 185 views)
Jan 12 '11 #1
3 1698
thinking would be more like this.
need to loop through the table rows

Expand|Select|Wrap|Line Numbers
  1. Public Function GetSideBannersDir() As DataSet
  2.  
  3.         Dim Conn As New SqlConnection(ConnectionString)
  4.         Dim CmdSelect As New SqlCommand("GetSideBanners", Conn)
  5.         CmdSelect.CommandType = CommandType.StoredProcedure
  6.  
  7.         Dim Da As New SqlDataAdapter(CmdSelect)
  8.         Dim Ds As New DataSet
  9.  
  10.         'Fill the Dataset
  11.         Try
  12.             Da.Fill(Ds)
  13.  
  14.             Dim i As Integer
  15.             Dim rowcount As Integer = Ds.Tables(0).Rows.Count
  16.             For i = 0 To rowcount - 1
  17.                 Dim FormatImageURL As String = Ds.Tables("Banners").Rows(i)("ImageUrlField")
  18.                 Ds.Tables("Banners").Rows(i)("ImageUrlField") = "/Data" & FormatImageURL
  19.  
  20.                 Context.Response.Write("<br><br>DB" & Ds.Tables("Banners").Rows(i)("ImageUrlField"))
  21.             Next i
  22.  
  23.  
  24.             'Context.Response.End()
  25.             Da.Update(Ds)
  26.  
  27.             Return Ds
  28.  
  29.  
  30.  
  31.         Catch ex As Exception
  32.             Throw New ApplicationException("Data Error")
  33.         Finally
  34.             Conn.Close()
  35.         End Try
  36.  
  37.     End Function
  38.  
Jan 12 '11 #2
OK, this is cleaner, but still not working
Sigh

Expand|Select|Wrap|Line Numbers
  1.  Public Function GetSideBannersDir() As DataSet
  2.  
  3.         Dim Conn As New SqlConnection(ConnectionString)
  4.         Dim CmdSelect As New SqlCommand("GetSideBanners", Conn)
  5.         CmdSelect.CommandType = CommandType.StoredProcedure
  6.  
  7.         Dim Da As New SqlDataAdapter(CmdSelect)
  8.         Dim Ds As New DataSet
  9.  
  10.         'Fill the Dataset
  11.         Try
  12.             Da.Fill(Ds)
  13.  
  14.             For Each dr As DataRow In Ds.Tables("Banners").Rows
  15.  
  16.                 Dim FormatImageURL As String = ("ImageUrlField")
  17.                 dr("ImageUrlField") = "/Data" & FormatImageURL
  18.  
  19.             Next
  20.  
  21.             Da.Update(Ds)
  22.  
  23.             Return Ds
  24.  
  25.  
  26.  
  27.         Catch ex As Exception
  28.             'Throw New ApplicationException("Data Error")
  29.         Finally
  30.             Conn.Close()
  31.         End Try
  32.  
  33.     End Function
  34.  
Jan 12 '11 #3
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.


Expand|Select|Wrap|Line Numbers
  1. Public Function GetSideBannersDir() As DataSet
  2.  
  3.         Dim Conn As New SqlConnection(ConnectionString)
  4.         Dim CmdSelect As New SqlCommand("GetSideBanners", Conn)
  5.         CmdSelect.CommandType = CommandType.StoredProcedure
  6.  
  7.         Dim Da As New SqlDataAdapter(CmdSelect)
  8.         Dim Ds As New DataSet
  9.  
  10.         'Fill the Dataset
  11.         Try
  12.             Da.Fill(Ds, "Banners")
  13.  
  14.             For Each dr As DataRow In Ds.Tables("Banners").Rows
  15.  
  16.                 Dim FormatImageURL As String = dr("ImageUrlField")
  17.                 dr("ImageUrlField") = "/" + Context.Application("SysDataDir") & FormatImageURL
  18.  
  19.                 Context.Response.Write("loop: " & dr("ImageUrlField"))
  20.  
  21.             Next
  22.  
  23.             Da.Update(Ds, "Banners")
  24.  
  25.             Return Ds
  26.  
  27.  
  28.  
  29.         Catch ex As Exception
  30.             'Throw New ApplicationException("Data Error")
  31.         Finally
  32.             Conn.Close()
  33.         End Try
  34.  
  35.     End Function
  36.  
Jan 13 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Scott M. | last post by:
I have created a strongly typed dataset and populated it with data in my data layer. I have confirmed that the DataSet does, in fact contain my data and that there is a schema governing this data...
12
by: Michael B Allen | last post by:
Is it legit to modify static data like the following code? #include <stdlib.h> #include <stdio.h> struct tbl { int i; char *s; };
4
by: Bill | last post by:
I have a DataSet that is serialized to a local disk. One of the testers recently experienced a problem where data was saved and the Tablet PC she was testing later went offline. When she restarted...
2
by: Ceri | last post by:
I have been trying to display dataset data in a Crystal Report in a Crystal Reports Viewer using VB.Net. Displaying the data from the default xtreme.mdb Access database was no problem, but when...
2
by: Zaphod Beeblebrox | last post by:
Hi There; This is a silly question but I have to ask this. I want to create a query (SQL statement would be good!) that will do the following: 1. modify the data in the field of my choice;...
7
by: Frank | last post by:
Years ago I wrote a program to read .lnk files, modify the data and rewrite the file. I modified it slightly and used it for .pif files. I can't find it nor can I find the API calls I used. ...
1
by: TimEl | last post by:
Hi. Using Perl, I want to modify data in an XML file and print out the entire modified file, not just the elements I modify. In CPAN I have found that XPath allows me to pinpoint the elements...
1
by: cday119 | last post by:
Hey In my database I have time formatted as a unix timestamp. I put that into a dataset. What is the best way to change those timestamps into a human readable date and time when the dataset is...
0
by: bbaamm | last post by:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) If FileUpload1.HasFile Then Try ' alter path for your project ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.