Tuesday, August 25, 2009

How to modify the content of the existing DataTable in C#?

Let said the existing DataTable dt has some existing value in column "A" and "B" at first row (Rows[0])

so,

dt.Rows[0]["A"] = You new value here;
dt.Rows[0]["B"] = You new value here;

dt.Rows[0].AcceptChanges();
dtAcceptChanges();

Thursday, August 13, 2009

concatenation in SQL

DECLARE @myList varchar(1000)


select @myList = COALESCE(@myList + ', ', '') + cast(p.xxx_spec as varchar(50))

from tableX p

where p.xxID IN (123, 1234)


SELECT 'Return Value' = @myList

Wednesday, July 29, 2009

Create Folder

System.IO.Directory.CreateDirectory(@"c:\NewFolder");
System.IO.Directory.CreateDirectory(@"c:\NewFolder\NewSubFolder");


// Specify a "currently active folder"
//Create a new subfolder under the current active folder
string activeDir = @"c:\testdir2";

string newPath = System.IO.Path.Combine(activeDir, "mySubDir");

// Create the subfolder
System.IO.Directory.CreateDirectory(newPath);

Tuesday, July 28, 2009

Convert from string to byte

public static byte[] StringToByte(string InString)

{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

Byte[] bytes = encoding.GetBytes(InString);

return bytes;
}

Color System.Drawing.Color Chart

System.Drawing.Color Chart






Monday, July 27, 2009

Array

The following code declares an array that can store 100 items starting from index 0 to 99.
int [] intArray;

intArray = new int[100];
int[,] numbers = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} };

string[,] names = new string[2, 2] { {"A","B"}, {"X","Y"} };
int[] numArray = {1, 3, 5, 7, 9, 11, 13};

foreach (int num in numArray)

{

System.Console.WriteLine(num.ToString());

}

Saturday, July 25, 2009

IsDate

    public bool IsDate(string sdate)
    {
        DateTime dt;
        bool isDate = true;
        try
        {
            dt = DateTime.Parse(sdate);
        }
        catch
        {
            isDate = false;
        }
        return isDate;
    }