473,378 Members | 1,542 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,378 software developers and data experts.

Datarow to string

Hi

How can I save all values in a system.data.datarow to a string? I need this
for error logging purposes.

Thanks

Regards
Mar 15 '08 #1
1 6063
Hi all,

I was currious what would be quicker, the stringbuilder or the stringwriter.
The results were almost the same, where the stringbuilder was slightly
faster.

The results of the actions are of course exactly the same

For those who are interested bellow the code

\\\
''To Build a example row
Dim dt As New DataTable
For i = 0 To 100000
Dim dc As New DataColumn
dt.Columns.Add(dc)
Next
Dim dr = dt.NewRow
For i = 0 To 100000
dr(i) = i.ToString()
Next
dt.Rows.Add(dr)

Dim stw As Stopwatch
Dim stw2 As Stopwatch
Dim Cycles = 100
For i = 1 To 10
stw = New Stopwatch
stw.Start()
For y = 1 To Cycles
'To Serialize it using StringBuilder
Dim sb As New System.Text.StringBuilder()

For Each dc As DataColumn In dt.Columns
sb.Append(dr(dc))
sb.AppendLine()
Next

Dim sbString = sb.ToString
Next
stw.Stop()


stw2 = New Stopwatch
stw2.Start()
For y = 1 To Cycles
'To Serialize it using StringWriter
Dim sw As New System.IO.StringWriter
For Each dc As DataColumn In dt.Columns
sw.WriteLine(dr(dc))
Next

Dim swString = sw.ToString
Next
stw2.Stop()

Debug.WriteLine("SB: " & stw.Elapsed.ToString & " SW: " &
stw2.Elapsed.ToString)
Next
///

Cor

Mar 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: vbMark | last post by:
When I call the below code what I get returned is the string "System.Data.DataRow" I don't understand how this works. What am I doing wrong? private string GetData(string strQuery) {...
6
by: André Fereau | last post by:
Hi, I wish to use a class derivated from DataRow. The rows within a table are created with the NewRow method of the DataTable class. So I writed a method NewSTMTTRNRow() in my class...
4
by: CaptRR | last post by:
I think this is the right group to post to, so here goes. My problem is this, I cannot update the datarow to save my life. Been on this for 2 days now, and still am no closer to figuring it out...
3
by: Sharon | last post by:
I have a DataRow that I need to send it to another process as a XML string by remoting. Bu I do not want the other process to be familiar with the schema or DataTable and DataRow structure, so I...
6
by: JIM.H. | last post by:
Hello I have; DataRow dr= dataSet11.myTable.NewRow(); And I am filling the fields of this datarow. Now I need to create a copy of this row as drCopy and change a few fields and add both to...
1
by: Arpan | last post by:
This is how I am dynamically adding a table to a DataSet: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'Create an empty DataSet Dim dSet As New DataSet ...
5
by: samoore33 | last post by:
I use the code below to search through a DataSet: Dim t As DataTable t = result.Tables("State") Dim strExpr As String strExpr = "id = '" & theState.ToString() & "'" Dim foundRows() As DataRow...
10
by: mcbobin | last post by:
Hi, Here's hoping someone can help... I'm using a stored procedure to return a single row of data ie a DataRow e.g. public static DataRow GetManualDailySplits(string prmLocationID, string
2
by: Ryan Liu | last post by:
Is DataRow uses DataRow and DataRow much efficient than DataRow? Thanks, ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. Ryan Liu Shanghai Fengpu Software Co. Ltd Shanghai , China
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.