使用select方法后如何显示数据表列 [英] how do i display data table columns after using the select method
问题描述
使用以下代码识别列后,如何显示数据表中列的内容:
how do i display the contents of a column from the data table after i have identified it using the code below:
DataRow[] foundrows = cvmanagerDataSet1.Tables["apps"].Select("apps Like '"+id+"'");
推荐答案
从您的问题来看,不清楚要显示的位置和用户界面的类型.
但是,让我尝试简化一下.
DataRow[]
foundrows将仅合并来自datatable
的已过滤行的集合.
您可以从索引中找到任何元素,例如
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 fromdatatable
.
you can find any of element from it''s index like
string fifthelement = foundrows[0].ItemArray[5].toString();
您可以像
那样绑定到gridview
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
这取决于您的环境.
您可以在windforms/或asp中绑定到DataGrid.不确定DataRow []是否可绑定.
从原始记录创建新表并不需要这样,结果不是什么大问题:
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:
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
注意:此功能从原始集中删除行(可能不是必需的).
然后,您可以轻松地绑定到任何ListView/DataGrid等.另一种方法是,如果要输出文本,则创建一些HTML
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
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
这篇关于使用select方法后如何显示数据表列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!