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

Selecting specific columns from a dataview?

P: n/a
Hello,

I have a complete table within a dataset.

I want a dataview to show particular filtered data - works great with
the dv.rowfilter.

But can I display only certain columns that are filtered?

Right now in my rowfilter I have something like this:

dv.RowFilter = "Title like '%Whales%' OR Genus like 'Megaptera'"

This prints all of the fields in the table (30). I want to show only 4
fields

I cannot get a away with:

dv.rowfilter = "select Title, Genus, [Climate ID], Endangered from
Animals where Title like '%Whales%' OR Genus like 'Megaptera'"

I get this error: Missing operand after 'Title' operator

*Note "Climate ID" is the name of a column (yes it has a space in it so
I bracketed it).

So in row filter you cannot put in a full sql statement....

The dataset cannot be changed.

Anyway to pull specific columns from this table?

Thanks,

Tmuld.

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

Add a tablestyle to your datagrid.

http://msdn.microsoft.com/library/de...stdatagrid.asp

http://msdn.microsoft.com/library/de...asicprimer.asp

Ken
--------------------
"Tmuld" <tm******@spliced.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hello,

I have a complete table within a dataset.

I want a dataview to show particular filtered data - works great with
the dv.rowfilter.

But can I display only certain columns that are filtered?

Right now in my rowfilter I have something like this:

dv.RowFilter = "Title like '%Whales%' OR Genus like 'Megaptera'"

This prints all of the fields in the table (30). I want to show only 4
fields

I cannot get a away with:

dv.rowfilter = "select Title, Genus, [Climate ID], Endangered from
Animals where Title like '%Whales%' OR Genus like 'Megaptera'"

I get this error: Missing operand after 'Title' operator

*Note "Climate ID" is the name of a column (yes it has a space in it so
I bracketed it).

So in row filter you cannot put in a full sql statement....

The dataset cannot be changed.

Anyway to pull specific columns from this table?

Thanks,

Tmuld.
Nov 21 '05 #2

P: n/a
Tmuld,

No you cannot create a dataview with less columns than its underlying
datatable.

A dataview is only a view on a dataset. Nothing more. It has a rowfilter
however not a columnfilter.

So you have to do it in your controls. What can with the standard controls
only be a problem for the datagrid. When it is a winform, look than at the
links Ken has provided, because to do it is a part of the datagrid..

I hope this helps,

Cor
Nov 21 '05 #3

P: n/a
Since I am doing a .ASP project the information Ken quoted will not
work right?

How would I do it from the controls? Example or link?

Thanks again?

Nov 21 '05 #4

P: n/a
Tmuld,

The samples are all using HTML. I made one without that and all in VBNet
code.

\\\Needs a datagrid on a webform
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim DS1 As New DataSet
Dim dT As New DataTable("Table Name")
dT.Columns.Add("Col1", GetType(System.String))
dT.Columns.Add("Col2", GetType(System.String))
dT.LoadDataRow(New Object() {"Tmuld", "Cor"}, True)
DS1.Tables.Add(dT)
DataGrid1.DataSource = DS1.Tables(0)
Dim b1 As New BoundColumn
Dim b2 As New BoundColumn
b1.DataField = "Col1"
b2.DataField = "Col2"
b1.HeaderText = "Question"
b2.HeaderText = "Answer"
DataGrid1.Columns.Add(b1)
DataGrid1.Columns.Add(b2)
DataGrid1.AutoGenerateColumns = False
DataGrid1.DataBind()
End Sub
///

I hope this helps a little bit?

Cor

I hope this helps,

Cor
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.