Tuesday, January 29, 2013

How to hide a Contentpane or any Controls in FormAlpha on a Button click event of FormBeta which loads as a dialog box on top of FormAlpha


Two steps are needed:
First, Form Alpha needs a public Fucntion called "hidePane()" whose sole purpose is to hide the Pane.
Second, Form Beta needs a reference to Form Alpha. I asume that Alpha creates generates Beta and shows it. In this case give Beta a constructor that takes a FormAlpha as parameter:
//Variable to store wich form created this form
FormAlpha creatorForm;

public FormBeta (FormAlpha Creator){
  InitializeComponent();
  creatorForm = Creator;
}
Instead of using the normal empty constructor to create FormBeta:
Form otherForm = new FormBeta();
otherForm.show();
use the newly created one and give it a Reference to Alpha with "this":
Form otherForm = new FormBeta(this);
otherForm.Show();
now all your ButtonClick even has to do is call the hidePanle():
creatorForm.hidePanel();
P.S. if you want to be able to unhide he Panel as well, we may have to change step 1 a little.

Sunday, January 27, 2013

How To: Reset Identity column in SQL Server


How To: Reset Identity column in SQL Server

This is one of those simple tip posts that may seem obvious and taken for granted by those of us who have been working with SQL Server for a while now but maybe a newbie or two out there will find this helpful.
Every so often (just this morning!) I find myself resetting an identity column value back to 0 after I've deleted all the existing records so the table gets a fresh start at primary key 1. Yes, I know all about primary keys not changing and how the value in the primary key doesn't matter and so on. Sometimes I just like the primary keys starting at 1.
The following line resets the Identity value for the Customer table to 0 so that the next record added starts at 1.

DBCC CHECKIDENT('Customer', RESEED, 0)

Have a nice day. :-|