I am writing a C# windows forms application. It is a MDI application with lots of seperate forms. They all need to get to tables within a DataSet. What is the best way to make this DataSet "Global" for all forms within the application ?
My main thought is to create a static class. Create a static method that returns the dataset. Is this good programming practise ???
Your application should have a data model somewhere. Ignore the UI for the moment and think about the business logic and the data layer. Typically your main application class (this is often MainForm, though if one is being strict it shouldn't be) will have a reference to a data model – for a simple application this might just be the data set.
Any UI views that refer to the data model should then be given a reference to it, possibly via a view-model (or presenter or similar) class if the binding process is more complex than being a direct editor of some part of the data model. Anything more than simple updates should be done with logic in the model layer, which is why you may need to write a class instead of just using a data set.
So the short answer is, put it in your main form class or your application class, if you have one, and pass a reference to it to the MDI children when they are created. But I would like you to understand why that is a good idea and how to extend it to more complex view/model situations.
I'm using the below code to search for a string(text) in Description using Lucene.Net. Its working fine. But when text has "-"(hyphen), its not returning the results. the length becomes zero. Could you let me know how to rectify this. Thanks in advance.
QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Description",
Query qryDesc = parser.Parse("Description" + ":" + text + "*");
TopDocs hits = searcher.Search(boolQuery, 10);
int length = hits.scoreDocs.GetLength();
It depends on the content of your text cell. If it's a single digit value ('0' or '1') then you can use Int32.Parse(), if it's some other text (e.g. "True", 'T', etc) then you will need to write your own conversion.