Skip to main content

Posts

Showing posts from September, 2010

How to edit GridView manually

Filling, Editing, Updating, Deleting from a GridView is quite easy now. Just follow these steps. 1. Open Visual Studio create a web based project. 2. Go to design view of Default.aspx page and then drag&drop a GridView control from standard Visual Studio Toolbox. 3.Right click on GridView goto properties and then disable AutoGeneratedColumns property to false. 4. Navigate to your source page (default.aspx). then we will found the tags look like asp:gridview id="GridView1" runat="server" autogeneratecolumns="False"> 5. Now, open tab in gridview and wirte the following code. 6. Save the File. Now goto your codebehind file(Default.aspx.cs) 7. Replace your Page_Load event with the following protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { fillgrid(); } } 8. And write the Grid method private void fillgrid() { con.Open(); da = new SqlDataAdapter("select * from login", con

How to Display Image from Database

//Retrieving image from Database SqlCommand c = new SqlCommand(); c.CommandType = CommandType.StoredProcedure; c.Connection = con; c.CommandText = "sp_readImage"; int id =Convert.ToInt16( obj.executescalar("select max(photoid) from Photos")); c.Parameters.AddWithValue("@id",id ); byte[] imagedata = (byte[])c.ExecuteScalar(); MemoryStream memory = new MemoryStream(imagedata); // To display the image in the page itself img =System.Drawing.Image .FromStream(memory); img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg ); // To Disaply image in image control(image1) BinaryWriter t = new BinaryWriter(File.Open(Server.MapPath("Images\\sample.jpeg"),FileMode.Create )); t.Write(imagedata); t.Close(); Ima

How to store image in a database in binary format

Create one empty web page and do the following things... 1.Drag & Drop FileUpload Control and one Button from standard Toolbox 2.Double click on button control it'll generate a button click event. In that event write the following code 3.business_logic is a class file and which is used for opening database conections, executing database queries,etc. You can may even directly declare directly the connections, commands in codebehind file(*.cs,*.vb) business_logic obj = new business_logic(); if (FileUpload1.HasFile) { // Storing image in Database BinaryReader reader = new BinaryReader(FileUpload1.PostedFile.InputStream); byte[] image = reader.ReadBytes(FileUpload1.PostedFile.ContentLength); string temp= obj.assignconn(); con = new SqlConnection(temp); con.Open(); cmd.Connection = con; cmd.CommandText = "sp_imageInsert"; cmd.CommandType = CommandType.StoredPr