Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 7th, 2005, 03:58 AM
Authorized User
Join Date: Jul 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in Parameter Object

Respected Forum Members,
        iam facing a problem in saving a picture image to my database table. Also i want to display the saved image in my VB.NET Form also.Though i bound the image property of a picturebox control to the DataTable Object (say table), the place where im facing an error message is in the btnAdd_Click() sub procedure in the section where value for Parameter @Photo is defined. Iam supplying value through FileName property of the OpenFileDialog Control. Also tell me can i supply value to @phone variable through image property of a PictureBox control.
For the sake of completeness of the problem mentioned, i would also like to tell you that in sql server 2000 i had used image data type for the Photo. But i didn't find any image datatype while defining stored procedure for the table. WHY IS IT SO ?

Below is the code of my project for your considerations. please HELP!!!

Private Sub BindFields()

        txtEmpID.DataBindings.Add("Text", table, "EmployeeID")
        txtFirstName.DataBindings.Add("Text", table, "e_FirstName")
        txtLastName.DataBindings.Add("Text", table, "e_LastName")
        txtDesignation.DataBindings.Add("Text", table, "Designation")
        txtAddress.DataBindings.Add("Text", table, "e_Address")
        txtCity.DataBindings.Add("Text", table, "e_City")
        txtPhone.DataBindings.Add("Text", table, "e_Phone")
        txtMobile.DataBindings.Add("Text", table, "e_Mobile")
        txtEmail.DataBindings.Add("Text", table, "e_Email")
        picEmployee.DataBindings.Add("Image", table, "Photo")

        StatusBar1.Text = "Ready"

    End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnAdd.Click

           dim objCommad as sqlCommand = New sqlCommand()

           objCommand.Connection = myConnection
            objCommand.CommandText = "INSERT INTO Employees " & _
       "VALUES(@EmployeeID, @e_FirstName, @e_LastName, " & _
      "@Designation, @e_Address, @e_City, @e_Phone, @e_Mobile, " & _
      "@e_Email, @Photo)"

            objCommand.Parameters.Add("@EmployeeID", txtEmpID.Text)
            objCommand.Parameters.Add("@e_FirstName", xtFirstName.Text)
            objCommand.Parameters.Add("@e_LastName", txtLastName.Text)
            objCommand.Parameters.Add("@Designation", Designation.Text)
            objCommand.Parameters.Add("@e_Address", txtAddress.Text)
            objCommand.Parameters.Add("@e_City", txtCity.Text)
            objCommand.Parameters.Add("@e_Phone", txtPhone.Text)
            objCommand.Parameters.Add("@e_Mobile", txtMobile.Text)
            objCommand.Parameters.Add("@e_Email", txtEmail.Text)

The above lines of code are working but the line of code below is creating a problem. I got the error message that "nvarchar and image type are incompatible"

 objCommand.Parameters.Add("@Photo", OpenImageFile.FileName)

I had tried to fix it by changing the above to this

objCommand.Parameters.Add("@Photo", picEmployee.image)

but still the problem isn't solved. I got the error message that "index( 0 based ) must be equal to or greater than 0 and less than the size of the argument list"


            Catch err As SqlException
            End Try



         End Sub

Hope this time my problem won't get ignored by the honourable forum members as i explained it in detail.

            thanking you

Old July 9th, 2005, 01:19 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

In SQL Server, the "image" datatype doesn't explicitly mean and image can go there. It is more general to define binary image data. This "image" can be a binary image of anything, in some cases an actual image. Take a look at the System.Data.SqlDbType enumeration, there is a member called "Binary" as well as one call "Image". "Image" is described as "A variable-length stream of binary data ranging from 0 to 231 -1 (or 2,147,483,647) bytes." This should satisfy your needs.

Unfortunately, I don't work with WinForms enough to know how to solve the rest of this problem. When dealing with dynamic binary data (images, uploaded documents, etc.) I seldom store them in the database, but rather store them on the server and store a path reference to them in the database. There are many folks who feel that you shouldn't store this type of binary data in the database because it drags down the DB engine. I won't get into this debate, I just want to share how I usually do this.

Old July 9th, 2005, 01:42 PM
Friend of Wrox
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india

hi peter,

u said tht u store images in the server and store a path reference to them in the database.

can u display images in Crystal Reports.
actually i m talking abt printing ID-Cards sort of report

plz help


Old July 9th, 2005, 01:51 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Sorry, I don't use Crystal reports either so I don't have any idea how they could bring up images.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter object malfunction - out parameter dash dev C# 2005 6 December 4th, 2007 12:58 PM
Session Parameter with Custom Object tna55 ASP.NET 2.0 Basics 8 February 6th, 2007 09:57 AM
How to get request object parameter vikas verma Pro JSP 0 December 22nd, 2004 12:52 PM
Object as parameter in a web service method evandro.paula .NET Web Services 3 October 14th, 2003 02:20 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.