Tuesday, April 6, 2010

join to remove values in tsql

I was looking at this post at stackoverflow. I found it interesting for those of us who are in to the tsql madness. well newbie sometime and a pro on the next..

Tuesday, March 16, 2010

Polymorphism in C#

so here's a basic question on Polymorphism in C#, i found at SO. looking for the basics these days.

class A {
public virtual void Method1(){}

public void Method2() {
Method1();
}
}

class B:A {
public override void Method1() { }
}

class main {
A myobject
= new B();
myobject.Method2();
}

So which function gets called?
B.Method1();

gets called because it properly overrides the virtual method A.Method1();

Monday, March 15, 2010

VB.Net equivalent of C# “As”

Here is an equivalance of the as of C# to VB programmers.

in C# you do this:

var x = y as String;
if (x == null) ...

in VB you do this :

Dim x As String = TryCast(y, String)
If x Is Nothing Then ...

meaning  "as" = "TryCast"



Thursday, March 11, 2010

Database Backup on Sql Server



Full Backup. This type of backup will lets you to backup all of extents of your database. In my previous articles, I've already explain about extent in SQL Server 2005. SQL Server always save your data in pages and extents. 1 pages contains 8 Kb of your data, and 1 extents is a group of 8 pages which contains 64 Kb data of your database. To use this type of backup, you must set your recovery model to full, before you backup your database. To set your database recovery model, you can use this query :

ALTER DATABASE [ database_name ]

SET RECOVERY [ FULL | BULK_LOGGED | SIMPLE ]

,and you can do full backup by using this query :

BACKUP DATABASE [ database_name ] TO DISK = '\' WITH INIT

TO DISK clause specify the location of your backup device, while WITH INIT clause is the common clause to tell SQL Server to overwrite existing data in backup device. You can make backup device by using SSMS or simply by using this query. Backup device is logical backup medium to save your backup data. It has extension .bak.

Differential Backup. This type of backup will backup your database since the last full backup. SQL Server will make extent map to recognize the new data in your database. When you insert data in your database, extent will have bit with 0 to 1 to represented their information. After you do full backup, it will be reseted to 0, in this way SQL Server know which data that have to be backed up in differential backup methods.Notes that you can do this type backup if you have done full backup to your database.

You can do differential backup by using this query :

BACKUP DATABASE [ database_name ] TO DISK = '\' WITH DIFFERENTIAL

Incremental Backup. This type of backup looks similar to differential backup. But actually, it's really different. Incremental backup will back up your database since the last full backup and the last incremental backup. So if you have 100 Mb data on Sunday, 150 Mb data on Tuesday, 200 Mb data on Wednesday, and 250 Mb data on Thursday. So the size of full backup data taken on Sunday is 100 Mb, while the incremental backup data taken on Tuesday, Wednesday, and Thursday are 50 Mb data for each day.

To restore this incremental backup, you must have all of your incremental backup data, or you won't be able to restore your database completely. For example, your incremental backup data on Wednesday is lost, you won't be able to restore your incremental backup data on Thursday. This type of backup are not recommended for production database, since it has a lot of risks.

Transaction Log Backup. This type of backup needs full backup of your database. Transaction Log Backup will back up all actives log files of your database. To use this type of backup you can use this query :

BACKUP LOG [ database_name ] TO DISK = '\' WITH INIT

You also can make operators and scheduled tasks to be assigned backup job to automated backup process of your database. I won't explain it this time, but I promise I'll tell you about this later.

Thursday, February 18, 2010

setting value to a RadDatePicker on load

I had to come with a page who has a link and returns to the selected values of a list . So here is the way i did it.


private void SetDateRequest(string dateValue, RadDatePicker datePicker, DateTime valueDate)
{
DateTime dateOut;
datePicker.SelectedDate = valueDate;
if (DateTime.TryParseExact(dateValue, "yyyy-MM-dd", null, DateTimeStyles.None, out dateOut))
{
datePicker.SelectedDate = dateOut;
}
}

and this is how I call it :

SetDateRequest(dateTo, ToDateRadDatePicker, endDate);


Cheers,

Tuesday, February 16, 2010

Error on TortoiseSVN installing on Windows 7

I made the upgrade to windows 7 enterprise edition this past weekend. But happen that when trying to install tortoise ver 1.6.7 the context menu did not show up. So I google around and found the answer:

Install the 32bit version of tortoise SVN parallel the 64bit version.
TC is a 32bit program and the 64bit shell extension can't be used by [u]any[/u] 32bit program.


this solved my problem to be able to export the projects from the code repository I was in urge for.

Cheers,

Tuesday, February 2, 2010

DateTime.ToString() display “A.M.” or “P.M.”


Is there any way to use the DateTime.ToString() method to display the meridiem of the time portion as "A.M." instead of "AM"?


here is the work around.

using System;
using System.Globalization;

class Program {
public static void Main() {
CultureInfo c = (CultureInfo)CultureInfo.CurrentCulture.Clone();
c.DateTimeFormat.AMDesignator = "A.M.";
c.DateTimeFormat.PMDesignator = "P.M.";
Console.WriteLine(DateTime.Now.ToString("tt",c));
}
}

This are a second way to try with a designator. But here you have a static date format and therefore miss the culture.


DateTime time = DateTime.Now;
string s = time.ToString("yyyy.MM.dd hh:mm:ss t.\\M.");
Console.WriteLine(s);



Cheers