Database Reference
In-Depth Information
transferring the demand to a file server. It does require more complicated coordination and has the
potential for database and data files to get out of sync. I won't use this technique in this chapter.
Tip If you are using a SQL Server Express database that cannot exceed 4GB or if you don't want your database
to store a lot of information and grow beyond a certain size limit, using SQL Server-provided text and binary data
types may be your only alternative for very large text and image data.
Within a C# program, binary data types map to an array of bytes ( byte[] ), and character data types
map to strings or character arrays ( char[] ).
Note DB2, MySQL, Oracle, and the SQL standard call such data types large objects (LOBs); specifically, they're
binary large objects (BLOBs) and character large objects (CLOBs). But, as with many database terms, whether
BLOB was originally an acronym for anything is debatable. Needless to say, it has always implied a data type that
can handle large amounts of (amorphous) data, and SQL Server documentation uses BLOB as a generic term for
large data and data types.
Storing Images in a Database
Let's start by creating a database table for storing images and then loading some images into it. We'll use
small images but use VARBINARY(MAX) to store them. In the examples, I'll demonstrate using images from
the code directory path C:\VidyaVrat\C#2012 and SQL 2012\Chapter17\Code ; you can use the path of the
location where you have some images on your computer.
Try It: Loading Image Binary Data from Files
In this example, you'll write a program that creates a database table and then load and stores images in
it.
1. Create a new Windows Forms Application project named Chapter17. When
Solution Explorer opens, save the solution.
2. Rename the Chapter17 project to Text and Binary Data. Rename the Form1.cs
file to LoadImages.cs . Select the LoadImages form by clicking the form's title
bar, and set the Size property's Width to 439 and Height to 178.
3. Drag a TextBox control to the form, and position it toward the center of the
form. Select this TextBox control, navigate to the Properties window, and set
the following properties:
Set the Name property to txtLoadImages.
 
Search WWH ::




Custom Search