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"
myConnection.Open()
Try
objCommand.ExecuteNonQuery()
Catch err As SqlException
MessageBox.Show(err.Message)
End Try
myConnection.Close()
BindFields()
End Sub
Hope this time my problem won't get ignored by the honourable forum members as i explained it in detail.
thanking you