Let's say I have two fields (one under another). By default I want to have both of them rendered, but when the first field is empty, I would like the second one to take its place. Is there any convenient way to achieve this?
Note: My problem is much more complex, and a "scalable" solution would be highly appreciated.
I've found a cumbersome method, but I'm still looking for something better.
I finally came up with a better solution. The solution is to create a table in a DataSet, and insert a subreport selecting the table as its data source. Now you can add rows dynamically to the table (depending on some conditions).
Related
I have some data that is displayed in a pivot table, from that pivot table I currently copy and paste them in another table with the corresponding current day, with so many operation numbers it takes about 1hr to complete this process daily, I'm trying to make a macro in which will help me in making this process in less time
This is the pivot table in which I copy the data
and here is where I paste it (in this table I use it to create some graphs)
Both tables consist of many different numbers of operation, as you can imagine this is very tedious.
Any help or ideas that can help me solve this is appreciated, I'm willing to try some other alternatives like fomulas, vba (preferred), even closedxml for c#.
I dont know if im explaining my self?
This is my logic.
Look for operation number
Copy Sum of "Sx"
Look in other sheet for the same operation number.
Paste value in corresponding day.
Look for same operation number with next "Sx"
.
.
End
Right now I'm just focusing on Operation1, since in Operation2 I use another sheet in which I do the same thing. (will probably use the same code as Operation1).
To clarify I'm not asking for someone to just give me the solution (although it is appreciated ), but any guide on this is helpful.
You do not need VBA to do this. Use GETPIVOTDATA.
Consider below replicated data:
In above sample, I copied some of your data in your screen shot, made a pivot out of it, put it in the same sheet and also put the table you need to populate below it. Then I use GETPIVOTDATA. I feel I need to show you how it is done even though it is well explained in the link I posted.
So we use this formula:
=GETPIVOTDATA("Sum of "&$I18,$I$2,"Date",J$17,"Opt",$I$16,"Id",$J$16)
in Cell J14. Take note that instead of using Day 1, Day2.. etc on your destination table, we used the actual date. Why? Because we need that in our GETPIVOTDATA Formula. Then copy the formula to the rest of the cells.
Result:
Now, GETPIVOTDATA errors out if it does not find anything which matches the criteria you supplied, so you might want to incorporate error handling using IFERROR statement.
Final Formula:
=IFERROR(GETPIVOTDATA("Sum of "&$I18,$I$2,"Date",J$17,"Opt",$I$16,"Id",$J$16),0)
Although you prefer VBA, I don't think a better approach than the built-in Excel functionality is more suitable in your case.
Before insert new value to table, I need change one field in all rows of that table.
What the best way to do this? in c# code, ore use trigger? if C# can you show me the code?
UPD
*NEW VERSION of Question*
Hello. Before insert new value to table, I need change one field in all rows of that table with specific ID( It is FK to another table).
What the best way to do this? in c# code, ore use trigger? if C# can you show me the code?
You should probably consider changing your design this doesn't sound like it will scale well, i would probably do it with a trigger if it is always required, but if not, id use ExecuteCommand.
var ctx = new MyDataContext();
ctx.ExecuteCommand("UPDATE myTable SET foo = 'bar'");
Looking at your comment on Paul's answer, I feel like I should chime in here. We have a few tables where we need to keep a history of each entry in that table. We implement this by creating a separate table for each. For example, we may have a Comment table, and then a CommentArchive table with a foreign key reference to the CommentId in the Comment table.
A trigger on the Comment table ensures that each time certain fields in the Comment table are updated, the "old" version (which is accessible via the deleted table in the trigger) gets pushed to the CommentArchive table. Obviously, this means several CommentArchive entries may exist for each Comment, but if you're only looking for the "active" comments, you just look in the Comment table. And if you need information about the history of a comment, you can easily use LINQ to SQL to jump from the Comment you're interested in to the CommentArchives that reference it.
Because the triggers we use in the above example only insert a single value into the Archive table for each update, they run very quickly and we get good performance. We had issues recently where I tried making the triggers more complex and we started getting dead-locks with as few as 15 concurrent transactions. So the lesson is that you should make these triggers simple, and make them touch as few rows in as few tables as possible.
For reasons that don't make a lot of sense (Read: Not my decision) I need to keep a large number of rows, about ~90,000, in a DataTable and I do not have the option of using a database.
I need to be able to search the DataTable efficiently to find rows that match some basic criteria. For example, I might be looking at a row that has the value 2 in two specific columns.
What is the best way to do this?
Edit: Please take a look at https://chat.stackoverflow.com/transcript/message/62648#62648 for more details; after I work on this I will try and summarize the extra details from the chat here as well as provide my solution.
You could easily use DataTable.Select()
The solution I ended up using for this painfully awkward and inconvenient situation was to use DataTable.Select(), populate a new DataTable and then use the same operation to select the rows I needed from the refined DataTable.
I think that this solution is clumsy, but then again the constraints on the problem were somewhat unrealistic seeing as I was on a tight schedule as well.
I have WPF DataGrid which get his data from Web Service. End user has ability to customize visible columns in DataGrid.
1st approach:
I get this data in xml and after convert xml to the dataTable and give it like ItemsSource for DataGrid.
2nd approach:
Also I can get this data like class array from service (for example Customer[])
Problem:
I use 1st approach with extra steps for the purpose not get redundant data from service.
In 2nd approach if user see only two columns in DataGrid (one column for one property in class) he get all class with all his filled properties (redundant data). in 1st approach he get only data xml which will be visible in datagrid in UI.
But I use MVMM approach in my project and I dont want to use xml and dataTable approach. I think I have to use 2nd approach, but in this case I get redundant data
In 2nd approach if user see only two columns in DataGrid (one column for one property in class) he get all class with all his filled properties (redundant data)
If the above is the only thing that is stopping you with your second approach, then C# v4.0 has Named and Optional Arguments feature. Which works as
Console.WriteLine(Calculate(weight: 123, height: 64));
even if the actual Calculate() has 99 arguments, with any order.
Please note, I assume, that by redundant you mean, unwanted data.
I would take the second approach even though this may transport a little bit more data. If you really want control over what fields are fetched, this will probably make your application more complex then necessary.
Have you verified you have performance problems with the second approach?
It is a just another trade-off we have always faced when developing softwares.
In your specific case,
First approach has performance advantage by transfering much less (not sure if really much) data on network and flexibilty by not using strongly typed data approach.
Second approach is looking better for manageability and easy development in the long term.
To choose the right approach you should consider and weighting non-functional requirements such as performance, extensibility, manageability etc.
Long story short, the database I'm using needs to get looked at. Until that happens, I need to make do with what I've been given (I know, I should fix it..).
I have a table that get populated via an external text file. I am not sure of the exact process as I'm relatively new to the company.
The table does not have a primary key as the entire table is dumped and re-loaded every quarter when there is a new text file.
Enter ASP.NET MVC. I need to display that table with checkboxes in a grid so the user can select some rows and send it back to the server. It sounds relatively easy, but I am really not sure what to put as the value for the checkboxes as I am pretty sure I'll need to use multiple columns to create a unique. Yep, I know, I know :).
OldTable
- Field1
- Field2
- Field3
...
- FieldN
The View
...
<input type="checkbox"
name="bunchOfStuff"
value"Field1Value,Field2Value,Field3Value"/>
...
Would something like this work? If I can create a key with a few fields, can I use those fields as the value in the checkbox? I realize my action will be a bit ugly as I'll have to split and parse each value in the array of values.
Wow, good luck with this!
I think your solution will certainly work and I can't think of a more elegant solution.
However I think you're going to be in deep trouble down the line. The thing that I would do would to be simply to put a Unique Identifer on the table that auto increments.
That shouldn't affect any of your processes or even your bulk insert application unless you insert using an ordinal field offset rather than named.
Sorry this answer isn't exactly what your looking for but the DB is just so bad that (any) answer presented I think will be equally bad.