C# - Datatable Subset Of Columns From Another Datatable
Jul 2, 2010
I have a datatable with 17 columns and a bunch of data. I wnat a datatable with only 6 of the columns and the data for those 6 columns. So I need a subset of the original datatable. How do I loop through the original datatable with 17 columns and end up with a datatable with only the 6 columns I want with the corresponding data for those 6 columns?
I am getting this error whilie bulding project. i simply has defined a datatable accessing its rows and columns. don't knw why it says Columns is not a member of 'DataTable.
Error 66 'Columns' is not a member of 'DataTable'. E:DOI1TableReports.aspx.vb 342 Error 65 'Rows' is not a member of 'DataTable'. E:DOI1TableReports.aspx.vb 297 Error 73 'NewRow' is not a member of 'DataTable'. E:DOI1TableReports.aspx.vb 410
i have the dataset with one table.Table contains three column like 'Name','Location','Pin'.I would like to move the data from another table based on schema.
If I am passed a datatable and I cant change the column structure..is there anyway to set an existing column to a Primary key so I can easily Find() the row I am looking for?
im trying to copying specific record from one datatable to another datatable i used below code
public System.Data.DataTable selectspecificdatarow(System.Data.DataTable dtg, int count, int startindex) { System.Data.DataTable dtn = dtg.Clone(); for (int i =startindex; i < count; i++)
[Code]....
its taking too long time in cloneing is there any better way to do this task which is Time effecent
i want to make a datagrid with 2 columns and many rows the columns i want to have databinding with a datatable
i want the 1 row 1 column of datagrid have data from 1 row of datatable i want the 1 row 2 column of datagrid have data from 2 row of datatable i want the 2 row 1 column of datagrid have data from 3 row of datatable i want the 2 row 2 column of datagrid have data from 4 row of datatable ...... ......
i use something like this
[code]...
but i have two times the same in tha datagrid left and right
Im trying to retrieve a datatable that I put into a session variable, however when i do it apears that there are no columns... I have done this before in VB.NET, I'n now using C#, and it worked perfectly, and as far as i can see there is no change in the code other than the obvious syntax changes.
EDIT: The dt (in part 2) variable has the right data when i look in the data visulization window, but i have noticed that the other properties associated with a datatable are abscent. When i hover over a normal looking datatable with my mouse it looks like the following: " dt ----- {System.Data.DataTable}" but in the class im working on it just looks like "dt ----- {}". Also, after I return the session variable into the dt I clone it (dtclone = dt.clone(); ) and the clone is empty in the data visulizer.... what on earth!
EDIT 2: I have now also tried converting the first datatable to a dataset, putting this in the session variable, and recoverting it back to a datatable in the class. Am starting to wonder if it is a probelm with: dt.Load(sqlReader); The data does appear after this step though in the dataset visualiser, but not after being cloned. Code below.
1) SQL command in a webhandler, the results of which populate the datatable to be put into the session variable.
DataTable dt = new DataTable(); SqlDataReader sqlReader= default(SqlDataReader); SqlDataAdapter sqlAdapter = new SqlDataAdapter(); sqlReader = storedProc.ExecuteReader(CommandBehavior.CloseConnection); dt.Load(sqlReader); System.Web.HttpContext.Current.Session["ResultsTable"] = dt;
2) Part of the code in a class which performs calculations on the table:
how to join two datatable datas into one datatable to show in one gridview
i.e in 1 datatable i have username and pwd and in another datatable i have that user details. how to show all these in one datatable to get those values display in gridview(asp.net)
I would like to bind 'Id', 'Name' and 'Email' from DataTable to RadComboBox. It's possible with ItemTemplate. But I don't want to display 'Email' column in the RadComboBox. I want display 'Email' in the label when the selectedIndexChanged. Is this possible?
I've built a User Control that contains a ListView. To make it work I need to pass to it a DataTable. The columns of this DataTable need to have particular names that match up with what the ListView is expecting. I have a large DataTable that I need to massage/convert over to this different format. To do that I need to filter out columns and rename the column names. The actual data in the DataTable doesn't need to change. Is there a good way to do this without actually instantiating a new DataTable and copying the data from the large DataTable into it?
HOW TO specify which columns are in a DataView from a DataTable. I want to create a DataView, that only has the columns from a DataTable that I choose, and in the order I want.
Example: // DataTable_MyTable ~~ Column #0 is for ID. I do not want my view to get this column. // DataTable_MyTable ~~ Column #1 is for TYPE. I want this column to come in 2nd place in my view. // DataTable_MyTable ~~ Column #2 is for NAME. I want this column to com in 1st place in my view.
DataView DataView_MyView = new DataView(DataTable_MyTable ~~ some how only get the columns I want, and in the order I want ~~);
// DataView_MyView now has only 2 columns. // DataView_MyView ~~ Column #0 is NAME. // DataView_MyView ~~ Column #1 is TYPE.
Dim dt As New DataTable Dim da As New SqlDataAdapter(s, c)
c.Open() if Not IsNothing(da) Then da.Fill(dt)
[code]...
When I call da.fill I am inserting all records from my query. I was then hoping to filter them to display only those where the GroupingID is equal to 0. When I run the above code. I am presented with all the data, the filter did not work. Please can you tell me how to get this working correctly.
I have a DataTable of available time slots. I have another DataTable of reserved time slots. I need to remove from the list of available slots the ones that have been reserved. The blocks are in 15 minute increments, but one of my problems is that the reservation can be longer than 15 minutes. I've had some luck removing one or two, but not all of the required columns.
I have two datatables, I want to get all records which are in one datatable but all matching records which exist in another datatable should not be available.
In terms of set, you can say that record which are in 1st datatable but not in 2nd DataTable.