March 29, 2017

How to minimize and maximize in C#.Net?

You have to set the forms WindowState property something like this:
In Windows Forms:
private void button1_Click(object sender, EventArgs e)
{
    this.WindowState = FormWindowState.Minimized;
}
In WPF:
private void button1_Click(object sender, RoutedEventArgs e)
{
    this.WindowState = WindowState.Minimized;
}

March 16, 2017

How do you truncate all tables in a database using TSQL?

When dealing with deleting data from tables which have foreign key relationships - which is basically the case with any properly designed database - we can disable all the constraints, delete all the data and then re-enable constraints


-- disable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

-- delete data in all tables
EXEC sp_MSForEachTable "DELETE FROM ?"

-- enable all constraints
exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"

If some of the tables have identity columns we may want to reseed them

EXEC sp_MSforeachtable "DBCC CHECKIDENT ( '?', RESEED, 0)"