select specific column from datatable
-
Hi, I have a datatable filled with data I get from a sql query and database. Has the following columns in: EmployeeID EmployeeName EmployeeSurname EmployeeSickLeaveDate I just want to select all the data from column "EmployeeName" in the datatable. By that, I only want to populate a new datatable with "EmployeeName" How will this be possible. I tried using datatable.select(), but no luck, or I am not using it correct.
-
Hi, I have a datatable filled with data I get from a sql query and database. Has the following columns in: EmployeeID EmployeeName EmployeeSurname EmployeeSickLeaveDate I just want to select all the data from column "EmployeeName" in the datatable. By that, I only want to populate a new datatable with "EmployeeName" How will this be possible. I tried using datatable.select(), but no luck, or I am not using it correct.
I would try this: I am assuming you are using vb.net Dim dt DataTable = firstDataTable.Clone() 'This removes EmployeeID dt.Columns.RemoveAt(0) 'This removes EmployeeSurname dt.Columns.RemoveAt(1) 'This removes EmployeeSickLeaveDate dt.Columns.RemoveAt(1) So now you have a new dataTable with only one column. Hope that helps. Ben
-
I would try this: I am assuming you are using vb.net Dim dt DataTable = firstDataTable.Clone() 'This removes EmployeeID dt.Columns.RemoveAt(0) 'This removes EmployeeSurname dt.Columns.RemoveAt(1) 'This removes EmployeeSickLeaveDate dt.Columns.RemoveAt(1) So now you have a new dataTable with only one column. Hope that helps. Ben
-
I would try this: I am assuming you are using vb.net Dim dt DataTable = firstDataTable.Clone() 'This removes EmployeeID dt.Columns.RemoveAt(0) 'This removes EmployeeSurname dt.Columns.RemoveAt(1) 'This removes EmployeeSickLeaveDate dt.Columns.RemoveAt(1) So now you have a new dataTable with only one column. Hope that helps. Ben
Provided of course that the ordinal of the columns doesn't change. This is a bit brute force and not really necessary.
only two letters away from being an asset
-
Hi, I have a datatable filled with data I get from a sql query and database. Has the following columns in: EmployeeID EmployeeName EmployeeSurname EmployeeSickLeaveDate I just want to select all the data from column "EmployeeName" in the datatable. By that, I only want to populate a new datatable with "EmployeeName" How will this be possible. I tried using datatable.select(), but no luck, or I am not using it correct.
First way would be to have the database query return only the column you are looking for. Otherwise try this
DataTable EmployeeName = new DataTable(); EmployeeName.Columns.Add("EmployeeName"); EmployeeName.Merge(fullDataTable);
only two letters away from being an asset