Personal Technology Information |
|
How to Save an Image in a SQL Server Database?
Most of the web applications have a lot of images used in it. These images are usually stored in a web server folder and they are accessed by giving the relative path to the file with respect to the root folder of the website. .Net being the platform for distributed application now, ASP.Net can be used to store images that are small to be stored in a database like SQL Server 2000 and later versions. For this purpose the SQL Server database provides a data type called "image" which is used to store images in the database. To access these images stored in the database we will be using the ADO.Net classes. To find out how to insert and retrieve an image in to the SQL Server database, you can create a .aspx page which can have a HTMLInputFile control which is used to select the image file that is to be saved in the database. You can also create a textbox control in which you can add the image name or some comment or an image id for the image saved. Use a button control to upload the image to the database. Namespaces like System.Data.SqlClient, System.Drawing, System.Data, System.IO, and System.Drawing.Imaging are used in this task. In the OnClick property of the button you can write the following code to upload an image to the database. // create a byte[] for the image file that is uploaded You can also write the above code in a function and call that function in the OnClick event of the upload button. The code given above performs the following steps in the process of inserting an image into the database. 1. Get the content length of the image that is to be uploaded To retrieve the image from the SQL Database you can perform the following steps. 1. Create a MemoryStream object. The code can be something like, MemoryStream mstream = new MemoryStream (); 2. Create a Connection object 3. Open the connection to the database 4. Create a command object to execute the command to retrieve the image 5. Use the command object's ExecuteScalar method to retrieve the image 6. Cast the output of the ExecuteScalar method to that of byte[] byte[] image = (byte[]) command.ExecuteScalar (); 7. Write the stream mstream.Write (image, 0, image.Length); 8. Create a bitmap object to hold the stream Bitmap bitmap = new Bitmap (stream); 9. Set the content type to "image/gif" Response.ContentType = "image/gif"; 10. Use the Save method of the bitmap object to output the image to the OutputStream. bitmap.Save (Response.OutputStream, ImageFormat.Gif); 11. Close the connection 12. Close the stream mstream.Close(); Using the above steps you can retrieve and display the image from the database to the web page. You can use these algorithms and take advantage of the "image" data type available in the SQLServer 2000 database to store small images that correspond to a particular record in the table of the database. This method of storing avoids the tedious task of tracking the path of the web folder if the images are stored in a web folder. Visit A Guide to .NET for a complete introduction to .NET framework. Learn about ASP.NET, VB.NET, C# and other related technologies.
MORE RESOURCES: From personal aircraft to e-bikes to robots: 5 tech innovations seen at CES Las Vegas Review-Journal Minnesota tech on display at country’s biggest consumer electronics show, with 3M leading the way Star Tribune Time to Finally Organize Your Digital Photos. First You Have to Find Them. - The Wall Street Journal Time to Finally Organize Your Digital Photos. First You Have to Find Them. The Wall Street Journal TOP 10 personal tech and gadgets of 2024 Designboom How AI Will Change Personal Tech in 2025 - Tech News Briefing - WSJ Podcasts The Wall Street Journal Shop the best Cyber Monday deals on phones, tablets, smartwatches and more Good Morning America Tech That Will Change Your Life in 2025 The Wall Street Journal Things to Try: Our 9 Top Tech Tips for You The Wall Street Journal The 28 Best Tech Gifts of 2024, According to Our Gadget Gurus The Wall Street Journal I’ve Been Driving an EV for a Year. I Have Only One Regret. The Wall Street Journal How Tech Created a ‘Recipe for Loneliness’ The New York Times Can You Turn Off Big Tech’s A.I. Tools? Sometimes, and Here’s How. The New York Times The Great AI Challenge: We Test Five Top Bots on Useful, Everyday Skills The Wall Street Journal Apple’s A.I. Is Landing Soon on iPhones. Here’s What It’s Like. The New York Times Android beefs up Bluetooth tag stalker protections The Register The Coolest Tech Gadgets We’ve Tested So Far This Year BestProducts.com Touch Screens Are Over. Even Apple Is Bringing Back Buttons. The Wall Street Journal Opinion | Why Is Technology Mean to Me? The New York Times The Data Big Tech Companies Have On You Security.org The Summer Is So Hot, Workers Are Wearing High-Tech Ice Packs The Wall Street Journal Apple Watch Is Becoming Doctors’ Favorite Medical Device The Wall Street Journal In the City, Personal Safety Starts With Your Smartphone The Wall Street Journal No way? Big Tech's 'lucrative surveillance' of everyone is terrible for privacy, freedom The Register Why Turning It Off and Turning It Back On Is Gadget-Fixing Magic The Wall Street Journal Apple Intelligence Isn’t Very Smart Yet—and Apple’s OK With That The Wall Street Journal What the Arrival of A.I. Phones and Computers Means for Our Data The New York Times China's homebrew Bluetooth alternative is on the march as Beijing pushes universal remotes The Register My Husband Wants a Japanese Toilet. Is He On to Something? The Wall Street Journal How I Got My Attention Span Back The Wall Street Journal How to Add Extra Security Layers to Your Phone or Tablet The New York Times Jonathan Haidt Blamed Tech for Teen Anxiety. Managing the Blowback Has Become a Full-Time Job. The Wall Street Journal The Only App That Always Wins the Battle for Your Attention The Wall Street Journal Exclusive | Wanted: Weekend Warriors in Tech The Wall Street Journal When Did Apple’s Notes App Become an Extension of Our Brains? The Wall Street Journal Foldables Are Becoming Good Enough to Be Your Next Smartphone The New York Times Amazon Wants Your Palm and TSA Wants Your Face. What Saying Yes Will Mean. - The Wall Street Journal Amazon Wants Your Palm and TSA Wants Your Face. What Saying Yes Will Mean. The Wall Street Journal How to Reduce Your Risk When Using Personal-Finance Apps The Wall Street Journal This Ring on Your Finger Tracks Your Sleep. Is It Worth the Splurge? The New York Times How to Turn Your Old iPhone Into an A.I. Phone (and Skip the Upgrade) The New York Times Report: Tech misconceptions plague the IT world The Register Tech Made Easy AARP A Case for Backing Up Your Precious Photos and Files at Home The Wall Street Journal I Tried a $1,000 Trash Can for Two Months—and I Get It The Wall Street Journal The Battle to Ban Screens From School Now Includes Chromebooks and Tablets - The Wall Street Journal The Battle to Ban Screens From School Now Includes Chromebooks and Tablets The Wall Street Journal The Hearing Aid Revolution That Wasn’t The Wall Street Journal How to Make Typing Easier on the Phone and Leave the Laptop at Home The New York Times China wants mobile devices to limit usage time for minors, ensure they only see nice content The Register Young Women With Eating Disorders Feel the Pull of Energy Drinks The Wall Street Journal How TikTok Is Wiring Gen Z’s Money Brain The Wall Street Journal PC shipments stuck in neutral despite AI buzz The Register Welcome to the Era of the A.I. Smartphone The New York Times Slack, Microsoft Teams, Google Chat: Is There Any Safe Place to Complain About Work Online? The Wall Street Journal |
RELATED ARTICLES
More Cool Web Tricks If you ask most people what frustrates them most about the Internet, many of them will tell you "It's the little things!"It seems like all the great tricks and tips that make people exclaim "STOP! How did you do that?" never make it into any manual (at least where I can find them).My father (and co-author of "Turn Words Into Traffic") calls it the "reverse oral tradition" of computing, where children teach parents the survival skills of PC life. A Peek Into the Near Future of Electronics Technology How long do you think DVDs have around? 20 years? 10 years? Actually, they have only been around for about seven years, but it seems like they have been around much longer. Many of us can hardly remember life before DVDs. Cisco Certification: A Survival Guide To The Cisco Cable Jungle One of the most confusing parts of beginning your Cisco studies is keeping all the cable types separate in your mind, and then remembering what they're used for. This often occurs when a CCNA or CCNP candidate starts putting together their own home practice lab, and they suddenly realize that they have the equipment to run labs, but not the cables. CCNA 640-801 Certification Primer The Cisco Certified Network Associate (CCNA) Certification is meant for career enhancement as well as gaining knowledge of the LAN/WAN technologies currently available for implementation. Hence, CCNA Certification can be obtained by IT professionals who have been a part of the industry for a considerable time and are interested in furthering their career in terms of role enhancement and salary. Tips for Buying a PC Buying Your PCBuying a PC that's right for you and your family is not all that simple task. More so if you're going to buy an unbranded or an assembled one. What's the Difference Between Plasma TVs and LCD TVs? Plasma and LCD TVs are the latest trend in home entertainment. Both offer unrivalled picture quality and resolution, while doing away with the bulkiness of the older rear-projection technologies. Is Your Web Browser Putting You At Risk? It's free, it comes with Windows and it's used by approximately 94% of the Internet population. It also poses an unacceptable security risk. Is Online DVD Rental or Pay-Per-View the Best Way to Get Your Movies? With renting methods such as online DVD rental and pay-per-view, it seems almost old-fashioned to go to the rental store. But with all the different ways to get the latest movies, which way is the best? Well, that depends on what is important to you. Flash Your nVidia Video Cards BIOS You will need the following:1. 1. Tips For Getting Technical Support Help Online Sometimes your PC will start acting strange for no apparent reason or a program which you use regularly will all of a sudden stop working as it should. This can be a frustrating experience especially if you have no idea where to go for help. Cisco CCNA Candidate FAQ CCNA FAQQ. What exams do I have to take to get my CCNA?A. Help, I Need a New HDTV! (Part 5 of 5) Feeling overwhelmed in selecting a new TV? With all the choices these days, you may feel like, "Where do I start?!"In the final part of our 5 part article, we the discuss tv recommendations by room.--Bedrooms and kids rooms. Cisco Certification: Building Your Own Home Lab, Part I CCNAs and CCNA candidates hear it all the time: ??Get some hands-on experience??. From my personal experience climbing the Cisco certification ladder, I can tell you firsthand that there is no learning like hands-on learning. 10 Easy Steps to Speed Up Your Computer - Without Upgrading 1. Empty the Temp directory regularly. 5 Simple Ways To Increase Your Computer Speed & Help Your Computer Run More Efficiently! If you're a computer expert, you'll probably already know about these tips (hopefully this will provide you with a little reminder). If you're not an expert, don't worry - these tips are simple, and don't require a lot of computer experience. D2X Digital SLRCoolpix 8800 Actually Refers to Two Nikon Cameras Addressing a D2X Digital SLRCoolpix 8800 search, this article provides a quick comparison of the Nikon D2X digital SLR and Coolpix 8800 cameras.Nikon D2X Professional Digital SLRCheck out a Nikon D2X review or two and quickly realize this is a world class professional digital SLR. The Benefits of the New Firefox Browser You probably heard of the new Firefox browser version 1.0 recently released by Mozilla. Cisco Certification: What To Expect On Exam Day Cisco Certification: Taking Your First Certification ExamYou've studied hard; you've practiced your configurations; you've used your flash cards over and over again; and finally, the big day is here. Your first certification exam!For many Cisco certification candidates, their first exam is the CCNA Composite exam or one of the two exams that make up the CCNA, the Introduction To Networking exam or the ICND (Interconnecting Cisco Networking Devices) exam. Are You Well Protected? Winter?the official start of the cold and flu season. Though, technically speaking, things got started a little early. Virtual Memory - What is It? I recently got an e-mail asking about virtual memory. The person who sent me the question was getting an error on random occasions from their Windows operating system stating "Your computer is low on virtual memory". |
home | site map |
© 2006 |