|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Return DataRowDim 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 Duh! What I am trying to say is that I need to return the foundRows as
an object. samoore33 wrote: Show quoteHide 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 wrote:
> I use the code below to search through a DataSet: foundRows is an array of DataRows, so return that from your function, as > > 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. 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. 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 Show quoteHide quote "samoore33" <samoor***@gmail.com> wrote in message news:1157031656.956712.26350@h48g2000cwc.googlegroups.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 > 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: Show quoteHide 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" <samoor***@gmail.com> wrote in message > news:1157031656.956712.26350@h48g2000cwc.googlegroups.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 > > 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? Show quoteHide quote > Public Function SearchXML(ByVal theState As String) As DataRow() --- WAS Show quoteHide quote> 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 "samoore33" <samoor***@gmail.com> wrote in message news:1157045214.858647.21640@e3g2000cwe.googlegroups.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" <samoor***@gmail.com> wrote in message >> news:1157031656.956712.26350@h48g2000cwc.googlegroups.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 >> > > |
|||||||||||||||||||||||