Tuesday, November 29, 2011 | | 0 comments

How to image insert to database

1.first add to button this button name is browse and
add to picture box this name is pcimg 

2.now brwose the image and load to image in picture box...coding is 




OpenFileDialog open = new OpenFileDialog();


            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
           if (open.ShowDialog() == DialogResult.OK)


            {
               Image img = new Bitmap(open.FileName);
                pcimg.Image = img.GetThumbnailImage(340, 165, null, new IntPtr());
                open.RestoreDirectory = true;
                Image thumbimage = pcimg.Image;
                pcimg.Image = thumbimage.GetThumbnailImage(100, 100, null, new IntPtr());


            }


3.now image convert to the byte.we can using filestream or MemoryStream..memory stream is better than filestream .......coding is 


                             byte[] emp_photo;                           
                             MemoryStream ms = new MemoryStream();
                             pcimg.Image.Save(ms, ImageFormat.Jpeg);
                             emp_photo = new byte[ms.Length];
                             ms.Position = 0;
                              ms.Read(emp_photo, 0, emp_photo.Length);


4.now add image to sql data base....image sql datatype is image
coding is
 
                            SqlParameter pm = new SqlParameter("@logo", SqlDbType.Image);
                            pm.Value = emp_photo;
                            cmd.Parameters.Add(pm);
                            cmd.ExecuteNonQuery();


| | 0 comments

How to Clear all textbox field in one form...?

mostly we are using in asp.net page redirect same page or using null values in each textbox.text... 

now i am using simple way ....get all textboxes in single textbox array and run the loop for example coding is..... 

public void empty()
        {
            TextBox[] textempty = { txtcategoryname, txtshortcode, txtdescription };
            for (int i = 0; i < textempty.Length; i++)
            {
                textempty.Text = string.Empty;
            }
        }

| | 0 comments

How to Get System name through C#

First using Namespace 
using System.Security.Principal;


and then 

Process.Start("C:\\Documents and Settings\\"+WindowsIdentity.GetCurrent().Name.Split('\\')[1]+ "\\My Documents\\Company Details.xls ");