I want to get the most frequent value for every column in my DataTable.
I found an answer to a similar question for a Table, but it does not seem to work for my DataTable.
Actually I would welcome a list of distinct values for every column.
Related
I need to compare two datatable and simply check if Datatable(A) contains rows which are in Datatable(B).
Then rows from (B) which will not be in (A) will be inserted into (A). So basically target is to insert rows from (B) into (A) but only those rows which are not already presented.
Both Datables have same structure, same columns and datatypes.
I donĀ“t want to do it with foreach loop for every Datarow(B) and compare with every Datarow in (A) it will be very slow solutions.
Thank you in advance
I am using c#.
I have thousands of rows in dynamodb like
Now I insert few more rows but with different columns
like
Here Row 3 and Row 4 are new rows
Now I need structure like below
Now I want old rows should have default 0 or blank string for new columns,
I don't want to iterate through old rows and updated items.
Is there any way to set default values..
What you're trying to achieve doesn't really work with NoSQL type databases. Technically, there is no concept of rows and columns when it comes to DynamoDB. Instead, there are items (your records) that contain any number of attributes. You can read more about it here.
If you're using an object mapper, I'd recommend dealing with this logic on that level, ie. when getting items from DynamoDB you can assign default values there if there is a need to do so.
This cannot be archived with a DynamoDB query. DynamoDB only "knows" about indexed keys (partition key, sort key and secondary indices) and is not able to tell you the name of all properties that exist in your table (unlike a relational database).
The only thing I can think of is:
Scan the entire database
Store all property names in e.g. a HashSet<T>
For each item: Add the missing properties, assing your default values and update it
I have a datatable with almost 20 columns in it. in another DT i get only the columns I want. Recently my requirements have changed i.e. Firstly the number of columns in the original DT were constant but now it increases or decreases depending upon the data.
So now, if I statically provide the column names I need in my new DT it isnt of much use to me.
Is there any way in which I can include those columns which may or may not be in the Original Datatable????
For eg: col1|col2|col3|.......col20.
The columns that may bve present or absent fall between col12 and col 16. Is there anyway in which I could make it work????
EDIT:
I want col1,col2,col3 and all columns aftr col12...can I do it???
You can have total number of columns from datatable using
DataTable.Columns.Count
So you will know how many columns are there and you will know which column is in datatable and which is not.
DataRow contains a Table property, which seems to return the entire Table for which this row belongs.
I'd like to know if I can use that table safely, or if there are gotcha's.
In http://msdn.microsoft.com/en-us/library/system.data.datarow.table.aspx documentation, it says "A DataRow does not necessarily belong to any table's collection of rows. This behavior occurs when the DataRow has been created but not added to the DataRowCollection.", but I know for a fact my row belongs to a table.
In terms of pointers, if each Row from DataTable points to original DataTable, than I'm good to go. Is that all 'Table' property does?
Just to explain why I'm trying to get entire Table based on a single DataRow:
I'm using linq to join two (sometimes more) tables. I'd like to have a generic routine which takes the output of linq (var), and generate a single DataTable with all results.
I had opened another question at stackoverflow (Join in LINQ that avoids explicitly naming properties in "new {}"?), but so far there doesn't seem to be a generic solution, so I'm trying to write one.
if you know the row is part of table than yes you can access it without any problem. if the possibility exists where the row may not be associated to a table than check if the property is null.
if(row.Table == null)
{
}
else
{
}
As long as it's not null, you can use it freely.
I need advice on how to go about a problem I have with sorting a DataView in C#.
I need to add a sort property to my DataView because I later need it when I call a Find on the DataView (which needs to have a sort property specified in order to work). I need the Find in order to properly map a DataRow to a DataGridViewRow. I currently just use the row index to map to the DataGridViewRow, but this won't work in all cases if the user physically moves rows, or changes the sort order in the DataGridView (UI) because then the ids no longer match-up/map.
When I create the DataView, I load in a DataTable to pass in for creation. This DataTable can be of any form, I do not know what the DataTable contains for columns and rows. Therefore, I cannot create a sort if I don't know any column names to sort by.
I was thinking of just taking the first column name (column[0]) - no matter what it is and using that to sort. But this seems kinda sketchy, no?
My question is, is there a better way to determine what to sort my DataView by when column names are unknown?
Thanks!
I haven't tried it, but since it sorts based on the column name you pass in, couldn't you sort based on index with something like:
dataview.Sort = dataview.Table.Columns[index].ColumnName + " DESC";