Hello Friends , In This Article I Will tell you how you can store image in Windows Desktop App In Database as Byte Format And Also Fetch Data From Database And Display Image Picture Box . So Let's Start .


Save Image In Row Format / Bytes Into Database in C# Windows Desktop Application

 

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application

 



Step : 1 Open Your Visual Studio  . And Create New Project From  File Menu > New > Project

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application


Step : 2 Select Windows Desktop App From Menu



Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application

Step : 3 Enter Your Project Name And Path Of Your Location Where You Want To Save Your Project

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application


Step : 4 Now Click On Next Button 

Step : 5 Create Design As You Want . As You See In Below Image Here I Only Add Text Box , Picture Box And Two Button For Browse Image And Save.



Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application



Step : 6 Now Add Data Base File From Right Click On Your Project Name From Solution Explorer Add > New File Or You Can Simply Use Short Cut Key Ctrl + Shift + A

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application


Step : 7 Select Service Based Database , Give Name As You Want And Click On Add

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application



Step : 8 Now Create New Table , To Create Table Double Click On Your Database File It Will Open Server Explorer Then Right Click On Table Add > new Table Add Fields In table As You Want But Make Sure You Use Image Datatype For Your Image Field.Below is The Image of Table Which i Create For this Project

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application


Step : 9 Now Copy Your Connection String By Right Click On Database Name > Modify Connection > Advance .


Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application

Step : 10 Now Add New SQL Connection On Your Form Load Event As Show In Below Image .

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application


Step : 11 Create Dialog For Select Image As Shown In Below Image Create object of OpenFileDialog , Set Filters If You Want And Give Your Selected Image To Picture Box .



Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application



Step : 12 Now Create Function For Create Image File As Row Format As Shown In Below Image .


Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application



Step : 13 Now Add Code On your Save Button . here i only store name and image in database table  as you see in below image

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application


Step : 14 Run your Application As Enter Data In All Fields And Select Image By Click On Browse Button And Save Data By Clicking Save Button .As You See In Below Image Data Of Image Store as Row Data In Table


Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application



Get Data From Database And Show Image In Picture Box


Step : 15 Create Design As You Want For Fetch Data From Table By Record Id .


Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application


Step : 16 Create Function For Display Image In Picture Box From Row Data As Shown In Below Image

Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application
Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application



Step : 17 On Search Button Or Textbox Leave Image Add Following Code As Shown In Below Image


Save  Image In Row Format / Bytes Into Database And Fetch From Database in C# Windows Desktop Application





Full Page Source Code 





I Hope You Find this Article helpful . if You Learn Anything From This Article Kindly Share With Your Friends. Thank You.