Lightweight Maintenance Screens

The following can easily be turned into a lightweight maintenance screen:

        private void Form1_Load(object sender, EventArgs e)
        {
            _Conn = new SqlConnection(“My Connection String”);
            _Adapter = new SqlDataAdapter();
            _Adapter.SelectCommand = new SqlCommand(“execute wsp_my_select_all”, _Conn);
            _Builder = new SqlCommandBuilder(_Adapter);
            _DS = new DataSet();
            _Adapter.Fill(_DS);
            dataGridView1.DataSource = _DS.Tables[0];
            dataGridView1.Columns[0].Visible = false;
            dataGridView1.Columns[“rowversion”].Visible = false;   
        }

        private void SaveBtnClick(object sender, EventArgs e)
        {
            //Do something useful with any exceptions here
            _Adapter.Update(_DS, _DS.Tables[0].TableName);
        }

What Dot Net Rocks Does Not Get About The GPL

In a number of recent Dot Net Rocks shows Carl Franklin has mentioned that Microsoft is not anti-open source, just anti-GPL. From his comments it appears that Carl does not understand that a given piece of code may be released under a number of licences.

The GPL is based upon copyright law.  By default you may not use someone else’s copyrighted code without permission.

With a commercial licence you are paid for the right to use the code. That is the price, if the price is too high don’t use the code.

GPL code is released on the condition that it is only built into an application or dll that only consists of GPL code or GPL compatible code.  This is the price of using GPL code. If the price is too high don’t use the code.

If you modify GPL code you only need supply the changed source (under the GPL) to the person you give the application to and only if they ask.  Some people do more and publish publicly but that is not part of the GPL.

There is no reason that a given piece of code cannot be released under multiple licences.  If you own the copyright you can sell the code commercially and release the code under the GPL. 

When To Branch in Version Control

When you are developing a product that has a live version, yet you wish to perform enhancements to the application.  How do you cope with the version control (you do use version control…) of fixes or enhancement to the live version.

The solution here is to use a branch.  The branch must be from the labelled point (you do label/checkpoint builds) used for the live build.  The trick is to keep the branches as small as possible and keeping as few maintained. It adds complexity to the development task but allows development to continue. Only create the branch at the point that you need to make changes.

Possible work-around for DatagridView bug

This is a link to a work around to the reentrant issue on a win forms DataGridView.

The reentrant issue raises it’s head when changing data in a DataGridView. InvalidOperation exceptions get raised a random time after the grid is changed. This implies that the DataGridView uses threads in the background yet it’s public methods are not thread-safe.

In order to solve this you should use the best practice of subclassing the UI controls and put the fix there.

Theoretically you should subclass all controls (see here) – but if pushed for time just do the complex ones (how many times will you bugfix a label?) or the subset that you use frequently – any app will mostly use 10 or so basic controls.

MSDN Magazine Lag Time

I have been reading MSDN Magazine (and it’s predecessors MSJ and Visual Developer) for a number of years now.

Until recently there has been upto a 5 year lag between an article being written and being able to use it in anger.

Today I finally found a use for an article written in June last year (only 8 months behind)!

A really useful feature  especially when combined with  Code Generation:

(I have given up on adding tags around XML) 

ItemGroup
    Compile Include="*.cs"
/ItemGroup

This allows code to be added to the project without having to explicitly edit the project file.  

Simple DataGridView Sample

This is almost all you need: 

            string connStr = “Data Source=(local);Initial Catalog=Northwind; Integrated Security=SSPI;”);
            SqlConnection conn = new SqlConnection(connStr);
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = “SELECT * FROM Products”;
            DataSet dataset = new DataSet();
            SqlDataAdapter dataadapter = new SqlDataAdapter(cmd);
            dataadapter.Fill(dataset,”FOO”);
            dataGridView.DataSource = dataset.Tables[“FOO”];
            dataGridView.Columns[0].Visible = false;