Connecting Tech Pros Worldwide Forums | Help | Site Map

Return DataRow

samoore33
Guest
 
Posts: n/a
#1: Aug 31 '06
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


samoore33
Guest
 
Posts: n/a
#2: Aug 31 '06

re: Return DataRow


Duh! What I am trying to say is that I need to return the foundRows as
an object.

samoore33 wrote:
Quote:
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
Phill W.
Guest
 
Posts: n/a
#3: Aug 31 '06

re: Return DataRow


samoore33 wrote:
Quote:
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.
Mike McIntyre
Guest
 
Posts: n/a
#4: Aug 31 '06

re: Return DataRow


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" <samoore33@gmail.comwrote in message
news:1157031656.956712.26350@h48g2000cwc.googlegro ups.com...
Quote:
>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
>

samoore33
Guest
 
Posts: n/a
#5: Aug 31 '06

re: Return DataRow


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:
Quote:
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" <samoore33@gmail.comwrote in message
news:1157031656.956712.26350@h48g2000cwc.googlegro ups.com...
Quote:
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
Mike McIntyre
Guest
 
Posts: n/a
#6: Sep 2 '06

re: Return DataRow


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?
Quote:
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" <samoore33@gmail.comwrote in message
news:1157045214.858647.21640@e3g2000cwe.googlegrou ps.com...
Quote:
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:
Quote:
>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" <samoore33@gmail.comwrote in message
>news:1157031656.956712.26350@h48g2000cwc.googlegr oups.com...
Quote:
>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
>
>

Closed Thread