Feb 9, 2008

sealed class usage

We recently started an internal academy in our company to improve our software development skills. The first meeting was about OOP fundamentals, it was really interesting (thanks Vesko for your efforts!). This question appeared as interesting for me - when should we use the sealed class.

Some collegues guessed it should be used in the most concrete classes, as they will not be used as a base classses, but I don't think so. After all - why should you say : "Hey, don't use this thing as a base class" explicitly after you know it will not be used anyway.

I did soem research on the net about the sealed class usage, it appeared it's common use is for classes with static methods. The example I've found was about Brush and Pen .NET
objects. They are sealed as they have only static fields like : .Blue and so on.

So when you are doing software you may keep in mind that you have that sealed thing to help you limit the inheritance of your classes.

Feb 6, 2008

Is Microsoft the source of all evil or what?

It is very strange, I was searching for a migration tools, just to see how this market is going. I accidently found this thing here:




What's so strange? Some people choose weird domains to run business under. The strange thing happened after I clicked on the link to see what's behind:



Finally I decided to type the url address in my browser to see actual site behind thesource.ofallevil.com and see where it redirected me:

>

Feb 4, 2008

5 minutes C# code to load CSV file into a DataSet


Step 1 : add button for browsing files, a textbox to hold the file name and paste the followin code in the browse button click handler (this code will basically popup a OpenFileDialog, set up to only open files with .csv extension):

             OpenFileDialog ofd = new OpenFileDialog ();
            ofd.Filter =
"CSV Files|*.csv" ;
            
if (ofd.ShowDialog() == DialogResult .OK)
            {
               
this .textBox2.Text = ofd.FileName;
                GetData();
            }

Then we need to get the file from the textbox2 and load it into data set:

      
private void GetData()
       {
            
FileInfo fi = new FileInfo (textBox2.Text);
            
OleDbConnection con = new OleDbConnection ( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fi.Directory.FullName + ";Extended Properties='text;HDR=Yes;FMT=Delimited'" );
            con.Open();

            
DataSet dsThings = new DataSet ();
            
OleDbCommand cmd = new OleDbCommand ( "SELECT * FROM " + fi.Name, con);
            
OleDbDataAdapter adapt = new OleDbDataAdapter (cmd);
            adapt.Fill(dsThings);
            
this .dataGridView1.DataSource = dsThings.Tables[0];
            
       }

As you can see we use OleDB provider to load the CSV file into the dataset.