473,399 Members | 2,278 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,399 software developers and data experts.

Return DataRow

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
foundRows = t.Select(strExpr)

This of course returns foundRows. My problem is that I need to return
the foundRows so that I can use that DataRow to display the information
that was found. I am terrible at explaining these things.

I originally looped through this and displayed the information in a
textbox. I have not been informed that I just need to return the
information and that it will be displayed outside of the function.

I am not sure how to return the foundRows information.

Any help would be appreciated.

Scott Moore

Aug 31 '06 #1
5 11615
Duh! What I am trying to say is that I need to return the foundRows as
an object.

samoore33 wrote:
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
foundRows = t.Select(strExpr)

This of course returns foundRows. My problem is that I need to return
the foundRows so that I can use that DataRow to display the information
that was found. I am terrible at explaining these things.

I originally looped through this and displayed the information in a
textbox. I have not been informed that I just need to return the
information and that it will be displayed outside of the function.

I am not sure how to return the foundRows information.

Any help would be appreciated.

Scott Moore
Aug 31 '06 #2
samoore33 wrote:
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
foundRows = t.Select(strExpr)

My problem is that I need to return the foundRows so that I can
use that DataRow to display the information that was found.

I am not sure how to return the foundRows information.
foundRows is an array of DataRows, so return that from your function, as
in:

Function XYZ(ByVal result As DataSet) As DataRow()
Dim t As DataTable
= result.Tables("State")
Dim strExpr As String _
= "id = '" & theState.ToString() & "'"
Dim foundRows() As DataRow _
= t.Select(strExpr)

Return foundRows
End Function

HTH,
Phill W.
Aug 31 '06 #3
Here is a code snippet from MSDN. It is a function that takes an array of
DataRows and processes each row to print it. I think it will explain how
you could process your foundRows.

.....
foundRows = t.Select(strExpr)
PrintRows(foundRows)
.....

Private Sub PrintRows(ByVal rows() As DataRow)
If rows.Length <= 0 Then
Console.WriteLine("no rows found")
Exit Sub
End If

Dim row As DataRow
Dim column As DataColumn
For Each row In rows
For Each column In row.Table.Columns
Console.Write("\table {0}", row(column))
Next column
Console.WriteLine()
Next row
End Sub
--
Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com
"samoore33" <sa*******@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
>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
foundRows = t.Select(strExpr)

This of course returns foundRows. My problem is that I need to return
the foundRows so that I can use that DataRow to display the information
that was found. I am terrible at explaining these things.

I originally looped through this and displayed the information in a
textbox. I have not been informed that I just need to return the
information and that it will be displayed outside of the function.

I am not sure how to return the foundRows information.

Any help would be appreciated.

Scott Moore

Aug 31 '06 #4
Thanks Mike, the printing out part I have. I want to pass it as an
object.

I have created a function that searches through the dataset, I want to
pass the information in the foundRows datarow as an object. I am going
to put my code in here:

Public Function SearchXML(ByVal theState As String) As DataSet

result.ReadXml("test.xml")

Dim returnTable As DataTable

Dim t As DataTable
t = result.Tables("State")
Dim strExpr As String
strExpr = "id = '" & theState.ToString() & "'"
Dim foundRows() As DataRow
foundRows = t.Select(strExpr) 'Returns items found

'Checks to make sure items were returned
If foundRows.Length = 0 Then
MessageBox.Show("That state is not in the list", "State
Does Not Exist", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Return result

End Function

I want the result variable to be populated with the datarow foundRows.

Scott Moore

Mike McIntyre wrote:
Here is a code snippet from MSDN. It is a function that takes an array of
DataRows and processes each row to print it. I think it will explain how
you could process your foundRows.

....
foundRows = t.Select(strExpr)
PrintRows(foundRows)
....

Private Sub PrintRows(ByVal rows() As DataRow)
If rows.Length <= 0 Then
Console.WriteLine("no rows found")
Exit Sub
End If

Dim row As DataRow
Dim column As DataColumn
For Each row In rows
For Each column In row.Table.Columns
Console.Write("\table {0}", row(column))
Next column
Console.WriteLine()
Next row
End Sub
--
Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com
"samoore33" <sa*******@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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
foundRows = t.Select(strExpr)

This of course returns foundRows. My problem is that I need to return
the foundRows so that I can use that DataRow to display the information
that was found. I am terrible at explaining these things.

I originally looped through this and displayed the information in a
textbox. I have not been informed that I just need to return the
information and that it will be displayed outside of the function.

I am not sure how to return the foundRows information.

Any help would be appreciated.

Scott Moore
Aug 31 '06 #5
See two changed lines in code below (maked: --- Was ...). Now the function
returns an ojtect that is an array of DataRows.

But perhaps you want to put the returned rows into a DataTable and return
that?
Public Function SearchXML(ByVal theState As String) As DataRow() --- WAS
DataSet

result.ReadXml("test.xml")

Dim returnTable As DataTable

Dim t As DataTable
t = result.Tables("State")
Dim strExpr As String
strExpr = "id = '" & theState.ToString() & "'"
Dim foundRows() As DataRow
foundRows = t.Select(strExpr) 'Returns items found

'Checks to make sure items were returned
If foundRows.Length = 0 Then
MessageBox.Show("That state is not in the list", "State
Does Not Exist", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Return foundRows --- WAS result

End Function

--
Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com
"samoore33" <sa*******@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Thanks Mike, the printing out part I have. I want to pass it as an
object.

I have created a function that searches through the dataset, I want to
pass the information in the foundRows datarow as an object. I am going
to put my code in here:

Public Function SearchXML(ByVal theState As String) As DataSet

result.ReadXml("test.xml")

Dim returnTable As DataTable

Dim t As DataTable
t = result.Tables("State")
Dim strExpr As String
strExpr = "id = '" & theState.ToString() & "'"
Dim foundRows() As DataRow
foundRows = t.Select(strExpr) 'Returns items found

'Checks to make sure items were returned
If foundRows.Length = 0 Then
MessageBox.Show("That state is not in the list", "State
Does Not Exist", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Return result

End Function

I want the result variable to be populated with the datarow foundRows.

Scott Moore

Mike McIntyre wrote:
>Here is a code snippet from MSDN. It is a function that takes an array
of
DataRows and processes each row to print it. I think it will explain how
you could process your foundRows.

....
foundRows = t.Select(strExpr)
PrintRows(foundRows)
....

Private Sub PrintRows(ByVal rows() As DataRow)
If rows.Length <= 0 Then
Console.WriteLine("no rows found")
Exit Sub
End If

Dim row As DataRow
Dim column As DataColumn
For Each row In rows
For Each column In row.Table.Columns
Console.Write("\table {0}", row(column))
Next column
Console.WriteLine()
Next row
End Sub
--
Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com
"samoore33" <sa*******@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegr oups.com...
>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
foundRows = t.Select(strExpr)

This of course returns foundRows. My problem is that I need to return
the foundRows so that I can use that DataRow to display the information
that was found. I am terrible at explaining these things.

I originally looped through this and displayed the information in a
textbox. I have not been informed that I just need to return the
information and that it will be displayed outside of the function.

I am not sure how to return the foundRows information.

Any help would be appreciated.

Scott Moore

Sep 2 '06 #6

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

Similar topics

3
by: Phil | last post by:
Hi, I have a client/server app. that uses a windows service for the server and asp.net web pages for the client side. My server class has 3 methods that Fill, Add a new record and Update a record....
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) {...
0
by: Ron Vecchi | last post by:
I am using the Select method on a DataTable to return a DataRow filter = (width LIKE '%width=\"%') I am getting an exception saying my filter is invalid I narrowed it down to the part that reads...
4
by: Michael Carr | last post by:
I have a function that populates a class with values from a database. I'd like to pass into the function either a SqlDataReader or a DataRow, depending on which mechanism I'm using to retrieve data...
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: News | last post by:
Hi, I wrote a function that pulls a record, below: ++++++++++++++++++++++++++++++++++++++++ Public Function getServPlanProgActivity( serviceprogramenroll_id As Integer, activity_id As Integer )...
11
by: Tim Frawley | last post by:
I need to return a DataRow or the Row Index in a DataSet wherein the value I am attempting to find is not a primary key. I have to do this often, more than 200 times when importing a file so it...
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...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.