http://codebind.blogspot.com/ https://www.youtube.com/user/codesonfire Skype: mijanashik Email: [email protected]

Project Name: C#.NET Save and Retrieve Image From Database

using using using using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Threading.Tasks; System.Windows.Forms; System.Data.SqlClient; System.IO; System.Configuration;

namespace CodeBind { public partial class frmImageSave : Form { public frmImageSave() { InitializeComponent(); } public static string GenerateString() { string returnValue = null; // Look for the name in the connectionStrings section. ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["CodeBind.Properties.Settings.CodeBindConnectionSt ring"]; //If found, return the connection string. if (settings != null) returnValue = settings.ConnectionString;

return returnValue; //return ConfigurationManager.AppSettings["ConnString"].ToString(); } private void btnSave_Click(object sender, EventArgs e) { string connString = GenerateString(); if (MessageBox.Show("Do you want to save this image to database?", "Confirmation") == DialogResult.No) return; try { SqlConnection Conn = new SqlConnection(connString); if (Conn.State == ConnectionState.Closed) { Conn.Open(); } SqlCommand cmd = new SqlCommand(); cmd.Connection = Conn; Cursor = Cursors.WaitCursor; byte[] img = null; FileStream fs = new FileStream(@txtImagePath.Text, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); img = br.ReadBytes((int)fs.Length); string sql = "INSERT INTO SavedImages(ImageName,ImageData, OriginalPath) VALUES('"+ txtFileName.Text +"',@IMG,'" + txtImagePath.Text + "')"; cmd.CommandText = sql; cmd.Parameters.Add(new SqlParameter("@IMG", img)); cmd.ExecuteNonQuery(); Conn.Close(); Cursor = Cursors.Default; MessageBox.Show("Image saved to database.", "Saved!"); LoadImageNames(); } catch (Exception ex) { MessageBox.Show(ex.Message); Cursor = Cursors.Default; } }

private void frmImageSave_Load(object sender, EventArgs e) { LoadImageNames(); } private void LoadImageNames() { try { string connString = GenerateString();

SqlConnection Conn = new SqlConnection(connString); if (Conn.State == ConnectionState.Closed) { Conn.Open(); } SqlCommand cmd = new SqlCommand(); cmd.Connection = Conn; Cursor = Cursors.WaitCursor; listImageName.Items.Clear(); cmd.CommandText = "SELECT ImageName FROM SAVEDIMAGES ORDER BY ImageName"; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { listImageName.Items.Add(reader[0].ToString()); } reader.Close(); Conn.Close(); Cursor = Cursors.Default; } catch (Exception ex) { MessageBox.Show(ex.Message); Cursor = Cursors.Default; } } private void bthShow_Click(object sender, EventArgs e) { SqlConnection Conn = new SqlConnection(GenerateString()); if (Conn.State == ConnectionState.Closed) { Conn.Open(); } SqlCommand cmd = new SqlCommand(); cmd.Connection = Conn; try { SqlDataReader reader; cmd.CommandText = "SELECT ImageData FROM SavedImages where ImageName='" + listImageName.Text + "'"; reader = cmd.ExecuteReader(); while (reader.Read()) { GetImage(pictureBox1, (byte[])reader["ImageData"]); } reader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } public static void GetImage(PictureBox PictureImage, Byte[] ImageValue) { try {

byte[] imageData = (byte[])ImageValue; //Initialize image variable Image newImage; //Read image data into a memory stream using (MemoryStream ms = new MemoryStream(imageData, 0, imageData.Length)) { ms.Write(imageData, 0, imageData.Length); //Set image variable value using memory stream. newImage = Image.FromStream(ms, true); } //set picture PictureImage.Image = newImage; //return PictureImage; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void listImageName_SelectedIndexChanged(object sender, EventArgs e) { bthShow_Click(sender, e); } private void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you want to delete this image?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) return; try { SqlCommandExecute("DELETE FROM SavedImages WHERE ImageName ='" + listImageName.Text + "'"); MessageBox.Show("Image deleted successfully.","Deleted"); frmImageSave_Load(sender, e); } catch(Exception ex) { MessageBox.Show(ex.Message); } } private void SqlCommandExecute( string sqlcode) { SqlConnection Conn = new SqlConnection(GenerateString()); if (Conn.State == ConnectionState.Closed) { Conn.Open(); } SqlCommand cmd = new SqlCommand(); cmd.Connection = Conn; cmd.CommandText = sqlcode;

cmd.ExecuteNonQuery(); } private static SqlDataReader DataReader(string sqlcode) { SqlConnection Conn = new SqlConnection(GenerateString()); if (Conn.State == ConnectionState.Closed) { Conn.Open(); } SqlCommand cmd = new SqlCommand(); cmd.Connection = Conn; SqlDataReader reader; cmd.CommandText = sqlcode; reader = cmd.ExecuteReader(); return reader; } private void btnBrowse_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); //dlg.InitialDirectory = ""; dlg.Filter = "Image File (*.jpg;*.bmp;*.png;)|*.jpg;*.bmp;*.png;"; DialogResult dlgRes = dlg.ShowDialog(); if (dlgRes != DialogResult.Cancel) { //Set image in picture box pictureBox1.ImageLocation = dlg.FileName; //Provide file path in txtImagePath text box. txtImagePath.Text = dlg.FileName; txtFileName.Text = dlg.SafeFileName; } } } }

C#.NET Save and Retrieve Image From Database..pdf

string connString = GenerateString();. Page 3 of 6. C#.NET Save and Retrieve Image From Database..pdf. C#.NET Save and Retrieve Image From Database..pdf.

424KB Sizes 5 Downloads 97 Views

Recommend Documents

C#.NET Save and Retrieve Image From Database..pdf
using System.Collections.Generic;. using System.ComponentModel;. using System.Data;. using System.Drawing;. using System.Linq;. using System.Text;. using System.Threading.Tasks;. using System.Windows.Forms;. using System.Data.SqlClient;. using System

pdf creator cnet free
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. pdf creator cnet ...

Distribute, Store and Retrieve Management Policies ...
I. INTRODUCTION. Management of Wireless ad-hoc networks has recently ..... very first solution (Strawman) is that when a link disappears, a broker behaves ..... [11] Cugola G., Nitto E.D., Fugetta A., “The Jedi event-based infrastructure and its ..

911ParrotAlert Search and Retrieve Protocolv.1 (1).pdf
Page 3 of 11. 911ParrotAlert Search and Retrieve Protocolv.1 (1).pdf. 911ParrotAlert Search and Retrieve Protocolv.1 (1).pdf. Open. Extract. Open with. Sign In.

pdf primo cnet
Page 1 of 1. File: Pdf primo cnet. Download now. Click here if your download doesn't start automatically. Page 1 of 1. pdf primo cnet. pdf primo cnet. Open. Extract. Open with. Sign In. Main menu. Displaying pdf primo cnet.

pdf compressor cnet
File: Pdf compressor cnet. Download now. Click here if your download doesn't start automatically. Page 1 of 1. pdf compressor cnet. pdf compressor cnet. Open.

adobe pdf cnet
Whoops! There was a problem loading more pages. adobe pdf cnet. adobe pdf cnet. Open. Extract. Open with. Sign In. Main menu. Displaying adobe pdf cnet.

pdf converter cnet download
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. pdf converter ...

Image processing in aerial surveillance and reconnaissance: from ...
Top and side view of 3D point cloud of the reconstructed scene (right). 4. ... In Figure 4-3 three different zoom levels for aerial video data are shown. ..... time or for forensic applications, Some image processing techniques such as image enhancem

Generalized Boundaries from Multiple Image ...
IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. .... In this example Gb uses color, soft-segmentation, and optical flow.

Generalized Boundaries from Multiple Image Interpretations
Feb 16, 2012 - ure/ground soft-segmentation that can be used in conjunc- tion with our boundary ..... also define matrix C of the same size as X, with each col-.

Generating Semantic Graphs from Image ...
semantic parser generates a unique semantic graph. G representing the descriptions of .... pseudo-code 1, shows that if Gcomb is empty then Gnext,. i.e. the next ...

Canonical Image Selection from the Web - eSprockets
An enormous number of services, ranging from Froogle. (Google's product search tool), NextTag.com, Shopping.com, to Amazon.com, all rely on being able to ...

Generalized Boundaries from Multiple Image ...
edge is clearly present in the output of a soft segmentation method. Right: in video, moving .... define NW × 2 position matrix P: on its i-th row we store the x and y ...

Canonical Image Selection from the Web - eSprockets
Google Inc.2. Georgia Institute of Technology ... Also, the previously used global features ... images, the logo is the main focus of the image, whereas in others it ...

Image retrieval system and image retrieval method
Dec 15, 2005 - face unit to the retrieval processing unit, image data stored in the image information storing unit is retrieved in the retrieval processing unit, and ...

save water save life pdf
Page 1 of 1. File: Save water save life pdf. Download now. Click here if your download doesn't start automatically. Page 1. save water save life pdf. save water ...

save water save life pdf
save water save life pdf. save water save life pdf. Open. Extract. Open with. Sign In. Main menu. Displaying save water save life pdf.

save girl save future.pdf
Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. save girl save future.pdf. save girl sav

cnet pdf editor freeware
Download. Connect more apps... Try one of the apps below to open or edit this item. cnet pdf editor freeware. cnet pdf editor freeware. Open. Extract. Open with.

free pdf maker cnet
Sign in. Loading… Whoops! There was a problem loading more pages. Whoops! There was a problem previewing this document. Retrying... Download. Connect ...

pdf to ppt converter cnet
File: Pdf to ppt converter cnet. Download now. Click here if your download doesn't start automatically. Page 1 of 1. pdf to ppt converter cnet. pdf to ppt converter ...