Link to home
Create AccountLog in
Avatar of RohitYadav
RohitYadav

asked on

creating a DataView with just one column from the DataTable

Hi,
I have a DataTable consisting of three columns.
I want to create a DataView which consists of first column of that dataTable.
I am fairly new to DataView and i now how to select  particular rows based on a condition but not aware how to select a full column.
Thanks
Avatar of CarlBoro
CarlBoro
Flag of United Kingdom of Great Britain and Northern Ireland image

dataview1.Table.Columns.Add(dataTableOne.Columns(0)) or  dataview1.Table.Columns.Add(dataTableOne.Columns("TitleOfColumn"))
Avatar of RohitYadav
RohitYadav

ASKER

Does not work. says object reference set to an Object.
It makes sense because the syntax you provided me adds a new column to the datatable that dataview depicts. I
I want my dataview to have just one column, I think we are supposed to use the constructor. But i am not sure about the "string rowfliter" parameter. Any other ideas?
ASKER CERTIFIED SOLUTION
Avatar of kewlchap_85
kewlchap_85
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I got the solution, You can use DefulatView.ToTable and specify the columns you want.
Thanks all who tried to help.
You got object reference not set to an instance of an Object because you didnt declare the object as New