•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 401,571 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,368 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 37113 | Replies: 6
![]() |
Hey guys next question
. Now I have having troubles with the IMAGE data type, can anyone provide examples on how to retrieve and update the image? I have tried the following:
But I recieved the lovely error "
Specified cast is not valid. "
help?
. Now I have having troubles with the IMAGE data type, can anyone provide examples on how to retrieve and update the image? I have tried the following: Dim imgdatastream As FileStream Dim imgdatalen As Integer Dim imgtype As String Dim n As Integer imgdatastream = Pic.PostedFile.InputStream imgdatalen = Pic.PostedFile.ContentLength imgtype = Pic.PostedFile.ContentType Dim imgdata() As Byte = New [Byte](imgdatalen) {} n = imgdatastream.Read(imgdata, 0, imgdatalen) Dim paramAvatar As SqlParameter = myCommand.Parameters.Add("@Avatar", SqlDbType.Image) paramAvatar.Value = n
But I recieved the lovely error "
Specified cast is not valid. "
help?

Formerly known as Slade.
Which line did you get the error on? I really haven't worked with the image data type before (i usually store an uploaded image on the server's file system), but I can play with it
.
. -Ryan Hoffman
ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
For this error it was this line
Cheers Tekmaven,
Slade
imgdatastream = Pic.PostedFile.InputStream
Cheers Tekmaven,
Slade
Formerly known as Slade.
Hey guys 
Well i've written some code to upload it
but now I have to get some to download it and display it ehehe...
Ok stored procedure:
and now the vb code...
And the html input button in the aspx page is:
and then of course you have to declare it in the server side code
PHEW! Finally done, now I need to know how the heck I can display these images on the page. Anyone got any ideas?

Well i've written some code to upload it
but now I have to get some to download it and display it ehehe...Ok stored procedure:
CREATE procedure sf_GetProfileImage @UserID nvarchar(20) AS SELECT Avatar, Av_type FROM sf_Members WHERE UserID = @UserID GO
and now the vb code...
Private Sub UpdateProfile(ByVal UserID As String) Dim imgstream As Stream = Pic.PostedFile.InputStream Dim imgdata(Pic.PostedFile.ContentLength) As Byte imgstream.Read(imgdata, 0, Pic.PostedFile.ContentLength) Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("strSqlConnectionString")) Dim myCommand = New SqlCommand("sf_GetProfileImage", myConnection) myCommand.CommandType = CommandType.StoredProcedure Dim paramUserID As SqlParameter = myCommand2.Parameters.Add("@UserID", SqlDbType.NVarChar, 20) paramUserID.Value = UserID Dim myReader As SqlDataReader myConnection.Open() myReader = myCommand.ExecuteReader Dim paramAvatar As SqlParameter = myCommand.Parameters.Add("@Avatar", SqlDbType.Image) paramAv_type.Value = Pic.PostedFile.ContentType Dim paramAv_type As SqlParameter = myCommand.Parameters.Add("@Av_type", SqlDbType.NVarChar, 100) paramAvatar.Value = imgdata myReader.Close() myconnection.close myconnection.dispose mycommand.dispose End Sub
And the html input button in the aspx page is:
< INPUT id="Pic" type="file" name="Pic" runat="server" >
and then of course you have to declare it in the server side code

Protected WithEvents Pic As System.Web.UI.HtmlControls.HtmlInputFile
PHEW! Finally done, now I need to know how the heck I can display these images on the page. Anyone got any ideas?
Formerly known as Slade.
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
.net access ajax asp backup business code combo crash custom daniweb data database developer development dom drive dropdownlist feed hacker hard hardware internet linux mail microsoft module msdn net news office qmail reader reuse security server skin smtp software sql storage survey theme vista weather web wikipedia windows xml xoap
- Get data out of excel file stored as an image (MS SQL)
- ASP/ Flash Integration using sql server 2000 (ASP)
- Identity Column Problem in MS SQL Server when moving data from using Bulk Copy (MS SQL)
Other Threads in the ASP.NET Forum
- Previous Thread: Link Button
- Next Thread: How to Search record from the Sql Server Database


Linear Mode