String format

string value1 = “Dot Net Perls”;

int value2 = 10000;

DateTime value3 = new DateTime(2007, 11, 1);

string result = string.Format(“{0}:{1:0.0}-{2:yyyy}”, value1, value2, value3);

//Output: DotNetPerls: 10000.0-2007

Convert Base64 String to Image

//Convert Base64 String to byte[]

byte[] imageBytes = Convert.FromBase64String(stringHere);

MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

//Convert byte[] to Image

ms.Write(imageBytes, 0 , imageBytes.Length);

System.Drawing.Image img = System.Drawing.Image.FromStream(ms, true);

img.Save(HttpRuntime.AppDomainAppPath + @”\test.png”);

Image1.Image = @”\test.png”;

Convert Image to Base64 string

public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format){

using(MemoryStream ms = new MemoryStream()){

//Convert Image to byte[]

image.Save(ms, format);

byte[] imageBytes = ms.ToArray();

//Convert byte[] to Base64 string

string base64String = Convert.ToBase64String(imageBytes);

return base64String;

}

}

DateTime from C# to SQL

string tempDate;

tempDate = Convert.ToDateTime(dataGridView1.CurrentRow.Cells[1].Value.ToString()).ToString(“yyyy-MM-dd HH:mm:ss”);

query = “UPDATE…WHERE CheckDate = CONVERT(datetime, ‘” + tempDate + “‘, 121)”;