By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

Return DataRow

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.