DB or not DB that is the question?

Megalith

Well-known member
Joined
Aug 21, 2006
Messages
66
Programming Experience
10+
I have been creating a database recently that counts various events amongst other things, in my solution i have been getting the values of certain cells in each row and creating a percentage which i am overlaying over some entries thru the paint cell event, my issue is this. do i incorporate these percentages into new columns in the database, do i create a new table for them or do i proceed down the route i began. the problem with the route i am taking is that the percentages arent sortable as the values sorted are the counting values attributed to the cell.
 
I'm not sure I completely understand your post but you may want to add an extra column to your table, either in the database itself or perhaps just in your local DataTable, that has its values computed from other columns. The DataColumn has an Expression property to which you can assign a string that represents how to calculate the value in a field from, more often than not, other values in the same row. This DataColumn can correspond directly to an evaluated column in the database or it can exist only in the local data, for the benefit of your grid. You could create your own column type that displayed a ProgessBar to indicate the percentage or use a regular text box column with its DefaultCellStyle.Format property set to "p" for percentage.
 
Most of the columns in the database table arent actually of any use as they are (e.g. a new player may have won 6 games out of 6 and another player has won 20 out of 2000 so sorting with 'games won' is misleading), conversion to a percentage makes more sense in terms of the end users point of view.

So hiding these columns and creating new columns with this expression property you mention seems to be the answer to my dreams.

I have to have a lot of respect for what this .NET can do, and i have so much to learn. Thanks jmcilhinney youve got my mind thinking lots of how to fix this issue.


As for the percentage bars i developed i might keep them as they allow the cell to be 'understood' clearer in some ways than a progress bar would (multi color linked to value:) )
 
i got it working using this idea i have one problem tho i cant use the derived column as an argument in a new derived column, can this be done or will i need to create this total in my database? i have 5 columns added together and then each column is divided by this total and * 100 (so all 5 add to 100%)
 
So are you saying that you have one column for which the Expression is something like:
VB.NET:
Col1 + Col2 + Col3 + Col4 + Col5
and then you want five other columns whose expressions will be something like:
VB.NET:
100 * Col1 / SumCol
I've never tried to do something like that but if it refuses then just do away with the intermediate column and perform the full calculation in each of the five percentage columns, e.g.
VB.NET:
100 * Col1 / (Col1 + Col2 + Col3 + Col4 + Col5)
 
I came to the same concluion overnight :) adding numbers doesnt carry much overhead :)

This works a treat now, i got the columns hidden i dont need except for ref purposes and the ones displayed with the percentages and bars drawn in them.

I found an excellent series of articles you wrote for the datagridview in C# and its shed a lot of light on the way this object functions. i spose i should start a new thread on this but is VB.NET and say C# essentialy the same animal once its been compiled? i notice how the code is almost identical nowadays ( bar the way the overall look of it appears)
 
All .NET languages are compiled to MSIL, not just VB and C#. You can write an app in VB, C#, J#, C++.NET, Delphi, etc. and they will all compile to essentially the same MSIL code if they do the same thing. The differences between languages are syntax and feature support.
 
It's an interesting subject, not to long ago VB was regarded as a platform for the amateur and home enthusiast, with C++ and java being the languages that professionals saught, many VB programmers have said of the advantages of VB over 'lower' level languages mainly the readability of the code, but the C++ programmers have always talked about classes and particularly Inheritance as being a huge no no for them, of course .NET has solved the inheritance issue. The Question now is what cant be done in VB.NET that can in C++.NET? if VB.NET can do anything C++ can then why use C++ at all, should we as programmers be all using a common easy to read language that anyone can understand, i for one dont know any C programmers that cant read basic but i know a lot of C programmers that dont know java.
 
There still differences between languages, even if there are many similarities. You can't do everything in .NET because the .NET Framework itself has to be written in something. Unmanaged C++ is still the most powerful option and will continue to be for a long time. VB.NET is a very powerful language but there are still things it cannot do. It doesn't share C#'s support for pointers for a start. Basically, choice is always a good thing, whether the difference between those choices is meaningful or not. As long as there are multiple programming languages available their creators will strive to make them better than the others in one way or another. That's good for developers.
 
i for one dont know any C programmers that cant read basic but i know a lot of C programmers that dont know java.

For me, it was the other way round. as a C-flavour programmer, I easily read java, c++, c, j++, j#, c# as they are very similar. basic, on the other hand, looks long winded, messy and overly-simplistic. I guess you could say I find VB similar to legal documents - they are written in my native language of english, but use too many words (to cover all eventualities) and become very hard to follow.

I dont know if you intended to draw a distinction when you said "read basic" vs "know java" but the two are different concepts - the french people use (mostly) characters that I recognise from english so i can read their words, even if I dont know their language. I would expect that all C programmers can read java (than basic) even if they dont know java.

vbn is similarly powerful to c# but it may take time to shake off its "numpty language" stigma, and I attribute a part of that to the default setting of Option Strict = OFF. Many VB programmers would question why:
Dim x as Date = "#01-Jan-2006#"

would make C# programmers cry, because their background doesnt lend them to understand the notions of strong typing. If VBN shipped with Option Strict ON it would have simultaneously: upset a lot of developers who didnt know (or care) about the difference between a date and a string, and it would have made VBN more like the strongly typed, mission capable, mature OO language that it is.
I am required to work in VBN on major projects, for no good reason other than the VB6/VBA guys think they would have a hope of understanding the code if I left the company. They file anything other than VB syntax in the "too hard" bin and that's a flipside hold-back - humans that are unwilling to change.

Until little things like that change, it may always have that false stigma of being a noddy language for less capable programmers :(



J notes that there are syntactical differences between .Net flavours that would also stop everyone from adopting one or the other. The following loop structure is impossible to create nicely in vb:
VB.NET:
for(string s = reader.ReadLine(); s != null; s= reader.ReadLine()){
  if(s.Equals(""))
    continue;
  //more code, etc
}
you have to use a while and as many goto statements as exist continue statements.. it's just not nice! :)
 
Last edited:
Thats a good point about the vb6 guys understanding the code, bosses these days always want staff to feel that they can be replaced with like a 'buses still run' attitude, it gives them the abality to refuse wage increases amongst other things and certainly if say the percentage of programmers on the market knowing C# is 5% of programmers knowing VB then its a no brainer for them as to what language skills they will seek, so i suppose a common languge has many drawbacks beyond the code limitations as your example illustrates. The boss would expect the longwinded solution than to empower you with using C# as he knows you will want a bigger cheque for this.

I love the word 'Numpty' btw dont here it often :)
 
Back
Top