|
HAHA! ITS YOU AGAIN!
Hi fella,
Hope your well. You know I just cracked it about 30 seconds before you mail came through. Although what i Did is slightly different. Would love your feedback on what I did ...
Created a method in my BuildLoopUps class thus:
public static void CreateLookups()
{
DataSet dsInstruments = BuildLookups.LoadXmlFile(@"LookUpXML\instrument_lookup.xml");
DataSet dsExtensions = BuildLookups.LoadXmlFile(@"LookUpXML\ext_look_up.xml");
}
With these properties at the top:
public static DataSet dsInstruments;
public static DataSet dsExtensions;
Then in my FileInformation class I can:
foreach(string _fileExt in BuildLookups.dsExtensions)
{
}
What are the operational differences between these two ways of doing it? That is of course assuming that my way does in fact work!
Thanks,
James.
|
|
|
|
|
Ahh, i forgot to say that this:
BuildLookups.CreateLookups();
is the line directly above the InitializeComponent(); which is doing the actual kick off of the build process ...
|
|
|
|
|
oh man ... i'm back to your original advice about Dictionaries ... I can't "foreach" over a dataset can I ... DOH!
|
|
|
|
|
You can foreach over the tables in a dataset. You just need to specific foreach (datatable tbl in dataset.Tables).
The main difference is, doing it in a static constructor will do it when the app starts, my way won't do it until the first time you use it, and if it takes a while to build, that's the toss up. Have the app start faster, or have it quicker the first time you ask it to do something.
Lazy initialisation works best when it's a resource that takes time or space and isn't used every time the program runs, then you don't pay the price for it, until you need it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Have the app start faster, or have it quicker the first time you ask it to do something.
Maybe we can slow down the speed of light and have both?
led mike
|
|
|
|
|
Gotcha! That does make a stack of sense ... it takes about 1-3 seconds foreach (geddit? har har) to import these two look ups and they are core to the functionality so are needed every time the app runs.
|
|
|
|
|
OK, so time is not that big a deal, but perhaps big enough that either way, your way makes more sense ( the static constructor )
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Gotcha.
Just a little quickie ... I get a warning on this line:
if (_fileExt == ThisRow[0])
Possible unintended reference comparison; to get a value comparison, cast the right hand side to type 'string'
I know that ThisRow[0] column contains a string, so it is safe to carry on without the .ToString()? As I understand it casting has an overhead that in this instance is not needed?
Thanks,
James.
|
|
|
|
|
I would obey the warning. A reference comparison means that you're checking if they are both the same string, not two strings with the same value. Big difference.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Not sure I follow, isn't this:
foreach (DataRow ThisRow in BuildLookups.dsExtensions.Tables["ext_look_up"].Rows)
{
if (_fileExt == ThisRow[0].ToString())
just saying foreach row in this table keep iterating until this string == (is the same as) the contents of ThisRow[0] (column 0)?
|
|
|
|
|
Well, you can cast it instead of calling tostring. Until you cast, it returns an object, so it compares the two objects to see if they are the same object. _fileExt and thisRow[0] may have the same value, but be different objects, different string instances.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
gotcha!
I know this is really cheecky but you've been so helpful in my endeavours to get my head into this I was wondering if I could ask a HUGE favour?
I don't feel confident in the general structure of what I'm doing in my app in terms of scope. I've just run into a scenario where I have a need for one of the lookups in the presentation layer but as I'm now building those in the data layer as you described they aren't available to the presentation layer.
feels like a huge 'gotcha' in a catch 22. Its a tiny app at the moment but would you be up for doing a brief code review if I emailed it to you?
Just some pointers on my 'coding myself into a corner' situation and wotnot. There are probably features of the language I've never encountered or heard about that would be the fix I'm looking for but I can't even ask questions about them as they are out of my field of vision.
Of course you can tell me to sling my hook!
James.
|
|
|
|
|
You can email me the code if you'd like, but I don't know how soon I'd have time to look at it. christian dot graus at gmail dot com
The best solution probably is to expose a method on the data layer that does the lookup you're after, but keep the data itself in the data layer.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Jammer wrote: I can't "foreach" over a dataset can I
No, and I'm still on .NET 2.0 but you can foreach over the rows in the tables in the DataSet.
led mike
|
|
|
|
|
hehe ... I just spotted my mistake in the code ... man, every time I reach for codeproject I say something daft and then after 30 seconds or so go ... "er ... ahhhhh" ...
|
|
|
|
|
Oh man I hate this error ...
"Object reference not set to an instance of an object." on this line:
foreach (DataRow ThisRow in BuildLookups.dsExtensions.Tables["ext_look_up"].Rows)
Whats the quickest way to actually debug issues like this. I always find myself getting a little confused by this one.
|
|
|
|
|
hmm ... my way doesn't seem to work ... i'm going to try this inside the same class that i'm using them in rather than having public instances of the lookups ... it doesn't seem to work they I tried.
all this failure can get a bit much sometimes ...
there are some really basic structuring things I still don't get about sharing things between classes that I'm sure is making my code a speghettification of logical hiccups ...
|
|
|
|
|
I've created a class that I want to turn into a UserControl but it has no need to be physically visible on the form - like the BackGroundWorker for example, it should only reside in the bar beneath the form in the IDE.
How do I do this?
Dave
|
|
|
|
|
You can add a background worker thread in the UI designer ? I find that pointless, why add it if it's not visible on the form ?
I guess you should look at how the background worker does it. My guess would be that there's an attribute on the class, if it's not derived from the Control classes, that makes it appear in the designer.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
There are several controls that behave like this. All the entries under the Components heading and Dialog heading in the toolbox at least. Adding/being visible in the designer is useful as the Properties Window is then available plus you can see what objects have already been created in InializeComponent().
Still haven't managed to figure this one out but I'll persevere.
Dave
|
|
|
|
|
Just got it!
The class needs to inherit from System.ComponentModel.Component instead of UserControl or Control
Dave
|
|
|
|
|
I am trying to create a UI for my DirectDraw interface that replaces the getto Today screen in Windows Mobile 6. I am using C# managed code to develop the interface.
I realize that there is something called DXUT in the .Net framework that provides functionalty of a UI elements such as a UI Button. Is there such thing for the mobile framework?
If not, I will have to implement my own button. How do i raise an event that checks if the mousetap is within bounds of a button? Do i actually have to implement the code to continously check if the mouse is inside the bounds of the button? Would that cause a high cpu utilization? Some kind of threading? please advice
|
|
|
|
|
hi,
i'm only starting with SQLServer 2005
the Questiuon is:
i have an app (C#) that is a client(in two computers for now).
Do i need to Create some sort of a Thread the will
Re Fill my dataset or does it's managed by the server
or maybe there's an Event that raises every time a Change is made
???
i'm confused
THANKS
Have Fun
Never forget it
|
|
|
|
|
You don't need to create special threads. There is no event in your application when a database change occurs. Your client app cannot tell when the database is changed unless you build your own system that informs all clients.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
So you're saying that i need in the SQLSERVER himself
some kind of an Event or ... to inform the clients
can u refer me to an article about it?
i've got lost searching in google and here
THANKS
Have Fun
Never forget it
|
|
|
|