Running trough a Table of a DataSet

T

Tor Inge Rislaa

I have a dataset with a table "Artikler". Before I bind the table to a
DataList in my Web Form I want to update the value of each row of the field
"PreText" in the table. (I don't want to update the database only the local
data of the DataSet Table) I want to replace all the occuranse of chr(13)
with the <br> tag.





01 myDataAdapter.Fill(myDataSet, "Artikler")

02 code for running trough the table and update the field "PreText" for
all rows

03 DataList1.DataSource = myDataSet.Tables("Artikler")

04 DataList1.DataBind()



I need some help filling in the code of line 02



TIRislaa
 
R

Rad [Visual C# MVP]

I have a dataset with a table "Artikler". Before I bind the table to a
DataList in my Web Form I want to update the value of each row of the field
"PreText" in the table. (I don't want to update the database only the local
data of the DataSet Table) I want to replace all the occuranse of chr(13)
with the <br> tag.





01 myDataAdapter.Fill(myDataSet, "Artikler")

02 code for running trough the table and update the field "PreText" for
all rows

03 DataList1.DataSource = myDataSet.Tables("Artikler")

04 DataList1.DataBind()



I need some help filling in the code of line 02



TIRislaa


You have 2 was of going about it
1) Replacing the newlines with <BR> as you output the datalist, using
the Replace method of the string object
2) Doing it in your sql statement such that the data already has the
<BR> inserted

Looping after loading will introduce a performance penalty, especially
if you have a lot of data

Depending on how many pages you have, method 2 might be less hassle
 
G

Guest

foreach (DataRow row in Artikler)
{

row["PreText"]=((string)row["PreText"]).Replace("\n","<BR>");
}

I think \n is the chr(13), if not then its the \r in the \r\n end of line
sequence.
Cheers.
Peter
 
T

Tor Inge Rislaa

The problem with the replacement in the SQL statement is that the datatype
of the datafield is TEXT and this is not a valid parameter within the
replace syntax. If you know of a better method then using replace in
Transact SQL I would like to know about it.
 
G

Guest

Ok, one more time: that should have been:

foreach (DataRow row in Artikler.Rows)

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top