Sharing the goodness…
Beth Massi is a Senior Program Manager on the Visual Studio team at Microsoft and a community champion for business application developers. Learn more about Beth.
More videos »
In SQL-Server we can store images inside database tables directly using the Image column type. And with .NET 2.0 data binding it can automatically convert these images (stored as byte arrays) into System.Drawing.Image classes for you. For instance, say you have a table called Pictures that has a column called Picture of the data type Image. You can create a new data source to this table to generate a strongly typed DataSet and use drag-and drop data binding to automatically display the image in a PictureBox. (For information on connecting to your database and creating strongly typed DataSets watch this video.)
If you don't see a PictureBox icon in the Data Sources window next to the Picture column in your DataTable, you may need to select the PictureBox to associate the byte array with the control:
Now you can drag-and-drop the Picture onto your form to set up the data binding to the PictureBox. The binding will automatically handle converting the byte array stored in the column into an image using the System.Drawing.ImageConverter. You can then set the SizeMode property on the PictureBox depending on how you want the image displayed; resized, stretched or otherwise.
But what if you just want to resize the image and not use a PictureBox? In that case you just need to convert the byte array stored in the Picture column into an System.Drawing.Image. Once you have that then you can use methods on this Image class to perform all sorts of transformations. To resize the image, just call GetThumbnailImage and pass it the new size requirements:
Dim resizeImg, origImg As Image
'Get the current row
Dim row As PictureDemoDataSet.PictureRow
row = CType(CType(Me.PictureBindingSource.Current, DataRowView).Row, _
'Convert byte array to image
Using ms As New System.IO.MemoryStream(row.Picture)
origImg = Image.FromStream(ms)
Dim width As Integer = 25
Dim height As Integer = 25
resizeImg = origImg.GetThumbnailImage(width, height, Nothing, Nothing)
I've attached a simple application that demonstrates these techniques for you to play with. You'll need Visual Basic 2005 and SQL Server 2005 (or Express) to run.
THANKS FOR "THE REZISING IMAGE STORED IN SQL SERVER" YOU 'VE MADE.
BUT COULD YOU TELL ME HOW TO ADD/EDIT IMAGE IN THE PICTUREBOX AND SAVED IN SQL SERVER IN IMAGE DATA TYPE?
I CAN CONNECT TO DATABASE, MAKE NEW DATASOURCE AND DRAG & DROP TO CREATE DATABINDING BUT I STILL DIDN'T KNOW MANIPULATE IMAGES.
Beth, you continue to add to the enjoyment of my retirement day with your interesting posts and videoes.
I recently completed a voice recognition project using an object I downloaded from the net. After buying my new Dell, I downloaded ORCAS and converted the project from express 2005 to 2008 and haven't been able to get it to work. I see that many people on the net have similiar interests. Could you post an example of a voice recognition program?
You just have to change the Image property of the picturebox and then call the BindingSource.EndEdit and then the TableAdapter.Update just like normal to update the data in your database.
I have same problem as EL.
I tried to load image from file using picturebox.load() method without no results. Maybe the Load method doesn't change image property correctly...
I don't know
OK BETH. Very well!!!
I solved the problem.
The solution is in the image porperty, updated through an instruction like this:
As I mentioned in the previous comment, you just have to set the Image property of the picturebox and then call the BindingSource.EndEdit and then the TableAdapter.Update just like you do to update other data-bound fields. The Image property is the property that is participating in the data binding when you drag-drop the image onto the form.
So I decided to post a summary of all the content the VB team members, including myself, have created
I am an Application Developer using VB.NET 2005 I had seen the movie you posted on your blog about the Forms on Data.
I wanted to know how to implement a search in a DataGridView during runtime. I have an options on the search like:
1. Ignore Case
2. No Options
3. Search Up
4. Search Down
These are the type of search I wanted to implement on my application.
Can you please give me an idea on how to do this.
I had made some reference on the sample codes that microsoft posted in there download site on VB.NET - specifically Regular Expressions in Search.
You can start with this video on building a search form: http://msdn2.microsoft.com/en-us/vbasic/bb643828.aspx
Thanks alot I did not see all the movies you posted, so it can be seen in movie 4.
I seen the movie on adding search capabilities, It is quite blurry and I want to know if this is the right command you entered in the query builder for the LastName in Filter:
LIKE @LastName * '%'
I only want to clarify things up cause I only get the FillbyLastLastName button and I didn't get the textbox in which the user will enter the LastName.
And another question:
How to assign the column when doing a query using select, I mean how to assign column(do I use @ after the field name), I know how to use the SELECT command like this?
SELECT column_name FROM table_name
WHERE column_name = constraints
When I do the WHERE clause in SELECT
I get a parameterized query error:
Error in WHERE clause near '@'.
Unable to parse query text.
I did it this way:
SELECT `Id`, `Surname`, `Firstname`, `Middle_Initial`, `Gender`, `Civil_Status`, `Address`, `Job_Position`, `SSS_No`, `TIN_No`, `PhilHealth`, `Pagibig`, `Date_of_Birth`, `Date_of_Employment`, `Employment_Status`, `Contact_No`, `Picture` FROM `british_armour`.`production_personnel`
WHERE 'Surname' = @Surname
is this correct, what is the right thing to do it.
That doesn't look like correct SQL syntax to me for SQL-Server (i.e. no quotes around field names and the table name looks incorrect). Have a look at SQL-Server books online for correct syntax: http://msdn2.microsoft.com/en-us/library/ms190659.aspx
I made corrections to my query commands and I solved it.
However I have a new problem. I deployed my application for testing purposes and I used Innosetup Compiler 5.1.14 (http://www.jrsoftware.org/isdl.php).
Everything works fine after the installation. I deployed it on my development machine and I find no flaws.
The error comes up when I install it on another computer and when I click the report button which I created from the videos on your blog on how to create a report using ReportViewer I get an error message:
The error is: Could not load file or assembly 'Microsoft.ReportViewer.WinForms, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I already add Microsoft.ReportViewer.WinForms to the Reference. And also add a namespace -
Using Imports Microsoft.Reporting.Winforms
I still can't generate report on other machines,
I still get the same error, but I can generate it on the machine in which I developed the software.
I will try the video you posted on deploying applications. The application will be use by multiple users on different departments.
I appreciate your help.
I solved my own problem regarding reporting. I let ReportViewer.exe be installed on their local machine.
Thanks for the support,