| | |
Working with SQL server's Image data type
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
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 AsInteger Dim imgtype AsString Dim n AsInteger imgdatastream = Pic.PostedFile.InputStream imgdatalen = Pic.PostedFile.ContentLength imgtype = Pic.PostedFile.ContentType Dim imgdata() AsByte = 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
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
.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
ASP.NET Syntax (Toggle Plain Text)
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...
PrivateSub UpdateProfile(ByVal UserID AsString) Dim imgstream As Stream = Pic.PostedFile.InputStream Dim imgdata(Pic.PostedFile.ContentLength) AsByte imgstream.Read(imgdata, 0, Pic.PostedFile.ContentLength) Dim myConnection AsNew 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:
ASP.NET Syntax (Toggle Plain Text)
< INPUT id="Pic" type="file" name="Pic" runat="server" >
and then of course you have to declare it in the server side code

ProtectedWithEvents 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.
![]() |
Similar Threads
- News Story: Which SQL Server 2008 edition is right for you? (MS SQL)
- SQL Server IMAGE and VB.NET (VB.NET)
- Get data out of excel file stored as an image (MS SQL)
Other Threads in the ASP.NET Forum
- Previous Thread: Link Button
- Next Thread: Need Help
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox class click commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu edit expose flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list listbox login menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news numerical objects order panelmasterpagebuttoncontrols problem radio ratings rotatepage save schoolproject search security serializesmo.table silverlight smartcard sql sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webservice wizard xml youareanotmemberofthedebuggerusers





