Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i display the contents of a column from the data table after i have identified it using the code below:
SQL
DataRow[] foundrows = cvmanagerDataSet1.Tables["apps"].Select("apps Like '"+id+"'");
Posted

From your question it's not quite clear that to where you want to display and type of UI.

But Let me try to simplify it.

DataRow[] foundrows will just cosist a collection of filtered row from datatable.

you can find any of element from it's index like

string fifthelement = foundrows[0].ItemArray[5].toString();


you can bind to gridview like

gridview.datasource = foundrows;


In short it is filtered source that you can apply to anywhere you choose.

But after filtering you can't find a data using column name like

foundrow["FirstColumn"] // compiler error


but yes you can use index to find first column like

foundrow[1] // will work
 
Share this answer
 
v2
Comments
[no name] 21-Jan-11 8:21am    
i want to display in a text box
Hiren solanki 21-Jan-11 8:26am    
It's a collection of rows so you can display it in a single text box but if you want value of one of the column only then you can do it like,

text1.Text = foundrow[2].ToString();
[no name] 21-Jan-11 8:36am    
when i write foundrow[6], it tells me the index is outta the bounds of the array
Hiren solanki 21-Jan-11 8:38am    
Then there must be only 6 columns there. and it's based on 0 index so if you want to find column 6 then use foundrow[5]
[no name] 21-Jan-11 8:53am    
this is the code am using and its still throwing up errors:


DataRow[] foundrows = cvmanagerDataSet1.Tables["apps"].Select("FileLoc Like '"+id+"'");

deldept.Text = foundrows[1].ToString();
Really it depends on your environment.

You cam bind to a DataGrid in windforms/or asp. Not sure if DataRow[] is bindable.

It's not a big ask to create a new table from the orignal and results like this:

VB
Private Function TransferDataToNewTable(ByVal newTableName As String, ByRef removeFrom As DataTable, ByRef rowsToTransfer As List(Of DataRow)) As DataTable
        Dim newTable = removeFrom.Clone()
        For Each dr As DataRow In rowsToTransfer

            newTable.ImportRow(dr)
            removeFrom.Rows.Remove(dr)
        Next
        Return newTable
    End Function


NOTE: this function removes the rows from the original set (may not be required).

Then, you can eaily bind to any ListView/DataGrid etc. Another way is to create some HTML if you want text output

VB
o = New System.Web.UI.WebControls.DataGrid
o.DataSource = ds
o.DataBind()

sw = New System.IO.StringWriter
hw = New System.Web.UI.HtmlTextWriter(sw)
o.RenderControl(hw)

Dim html = sw.ToString


Hope that helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900