How can I display image from a Sql Server database
VB.NET ’Function Public Function showImage(empid As Int32) As Byte() Dim myconnection As New SqlConnection(‘Server=localhost;uid=sa;password=;database=northwind;’) Dim mycommand As New SqlCommand(‘Select Employeeid, FirstName,Photo from Employees where employeeid =’ + empid.ToString(), myconnection) myconnection.Open() Dim dr As SqlDataReader = mycommand.ExecuteReader() dr.Read() Dim imgbyte As Byte() = CType(dr(‘Photo’), Byte()) Return imgbyte End Function ’showImage ’In Page_Load Dim data As Byte() = showImage(2) Dim offset As Int32 = 78 Dim mstream As New System.IO.MemoryStream() mstream.Write(data,offset,data.Length -offset) Dim bmp As New System.Drawing.Bitmap(mstream) bmp.Save(Server.MapPath(‘sample.jpeg’), System.Drawing.Imaging.ImageFormat.Jpeg) mstream.Close() Image1.ImageUrl = Server.MapPath(‘sample.jpeg’) C# //Function public byte [] showImage(Int32 empid) { SqlConnection myconnection = new SqlConnection (‘Server=localhost;uid=sa;password=;database=northwind;’); SqlCommand mycommand = new SqlCommand (‘Select Employeeid, FirstName,Photo from Employees where employeeid =’ + empid, myconnection); myconnection.Open (); SqlDataReader dr= mycommand.ExecuteReader(); dr.Read(); byte[] imgbyte =(byte[]) dr[‘Photo’]; return imgbyte; } //In Page_Load byte[] data = showImage (2); Int32 offset =78; System.IO.MemoryStream mstream = new System.IO.MemoryStream (); mstream.Write(data, offset, data.Length – offset); System.Drawing.Bitmap bmp= new System.Drawing.Bitmap(mstream); bmp.Save(Server.MapPath (‘sample.jpeg’), System.Drawing.Imaging.ImageFormat.Jpeg ); mstream.Close(); Image1.ImageUrl = Server.MapPath(‘sample.jpeg’);
I am using GDI+ to write on a bitmap. I know how to make font Italic/Bold. What should be done to apply both Italic and Bold
VB.NET dim fntFont as Font = new Font(‘Arial’,16,FontStyle.Italic|FontStyle.Bold ) C# Font fntFont =new Font(‘Arial’,16,FontStyle.Italic|FontStyle.Bold ) ; For more details refer FontStyle Enumeration
Why do I get the error message ‘A generic error occurred in GDI+.’
Give the proper path of the file. Check your permissions on the server where you are trying to write/read the files
How to remove the Cache starting with ‘cachedata_’
VB.NET Dim enumerator As IDictionaryEnumerator = Cache.GetEnumerator() While enumerator.MoveNext() Dim key As String = CType(CType(enumerator.Current, DictionaryEntry).Key, String) If key.StartsWith(‘cachedata_’) Then ’ Print it: Response.Write((‘Deleting key ‘ + key + ‘ ‘)) ’ Remove it: Cache.Remove(key) End If End While C# IDictionaryEnumerator enumerator = Cache.GetEnumerator(); while(enumerator.MoveNext()) { String key = (String) ((DictionaryEntry) enumerator.Current).Key; if(key.StartsWith(‘cachedata_’)) { // Print it: Response.Write(‘Deleting key ‘ + key + ‘ ‘); // Remove it: Cache.Remove(key); } }
Is there a Cache.RemoveAll()? How can I clear / remove the total cache
VB.NET Dim objItem As DictionaryEntry For Each objItem In Cache ’Response.Write (objItem.Key.ToString ()); Cache.Remove(objItem.Key.ToString()) Next C# foreach(DictionaryEntry objItem in Cache) { //Response.Write (objItem.Key.ToString ()); Cache.Remove(objItem.Key.ToString () ) ; }