473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Trying to add image to sql2K DB

I was, for the most part, following the directions at
http://aspalliance.com/articleViewer.aspx?aId=138&pId= . I shortened mine a
bit so that I only have to click browse, select my image and hit the submit
button. I get this error though when I try:
Server Error in '/' Application.
--------------------------------------------------------------------------------

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct
format.

Source Error:
Line 12: Dim ImageStream As Stream
Line 13:
Line 14: intImageSize = File1.PostedFile.ContentType
Line 15: strImageType = File1.PostedFile.ContentType
Line 16: ImageStream = File1.PostedFile.InputStream

Source File: E:\hhsinternal\tests\sqlimage.aspx.vb Line: 14

Stack Trace:
[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions .ParseDecimal(String
Value, NumberFormatInfo NumberFormat) +193
Microsoft.VisualBasic.CompilerServices.Conversions .ToLong(String Value)
+72

[InvalidCastException: Conversion from string "image/x-png" to type 'Long'
is not valid.]
Microsoft.VisualBasic.CompilerServices.Conversions .ToLong(String Value)
+227
sqlimage.Button1_Click(Object sender, EventArgs e) in
E:\hhsinternal\tests\sqlimage.aspx.vb:14
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
+78
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50215.44; ASP.NET
Version:2.0.50215.44

Here is my code:

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient

Partial Class sqlimage
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim intImageSize As Int64
Dim strImageType As String
Dim ImageStream As Stream

intImageSize = File1.PostedFile.ContentType
strImageType = File1.PostedFile.ContentType.ToString
ImageStream = File1.PostedFile.InputStream

Dim ImageContent(intImageSize) As Byte
Dim intStatus As Integer

intStatus = ImageStream.Read(ImageContent, 0, intImageSize)

Dim objConnection As SqlConnection
Dim objCommand As SqlCommand

objConnection = New
SqlConnection(ConfigurationManager.AppSettings("ap hrodite_test"))
objCommand = New SqlCommand("sp_addimage", objConnection)

objCommand.CommandType = CommandType.StoredProcedure

Dim InsertImage As New SqlParameter("@ImageFile", SqlDbType.Image)
InsertImage.Value = ImageContent
objCommand.Parameters.Add(InsertImage)

Dim InsertImageType As New SqlParameter("@ImageFileType", SqlDbType.VarChar,
255)
InsertImageType.Value = strImageType
objCommand.Parameters.Add(InsertImageType)

Try

objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
Response.Write("Success")

Catch ex As Exception

Response.Write(ex.Message.ToString)

End Try
End Sub
End Class
This is my Stored Procedure on the sql box:

Create Proc sp_addimage
@ImageFile Image,
@ImageType varchar(255)
AS
BEGIN
INSERT INTO test.imagetest (photoimage, photoimagetype)
VALUES (@ImageFile, @ImageType)
END
GO
I have a database called test with a single table called imagetest with
three columns:

ID int IDENTITY,
photoimage image,
photoimagetype varchar(255)
Any help would be appreciated. If someone knows of an easier way to insert
an image into a sql 2000 table without using stored procedures, that'd be
great too! I only know how to use VB. C# would just leave me scratching my
head.

Thanks,
Jim
Nov 19 '05 #1
1 1388
Perhaps this code sample will work out better for you:
http://SteveOrr.net/articles/EasyUploads.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Jim in Arizona" <ti*******@hotmail.com> wrote in message
news:O6**************@TK2MSFTNGP14.phx.gbl...
I was, for the most part, following the directions at
http://aspalliance.com/articleViewer.aspx?aId=138&pId= . I shortened mine a
bit so that I only have to click browse, select my image and hit the submit
button. I get this error though when I try:
Server Error in '/' Application.
--------------------------------------------------------------------------------

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a
correct format.

Source Error:
Line 12: Dim ImageStream As Stream
Line 13:
Line 14: intImageSize = File1.PostedFile.ContentType
Line 15: strImageType = File1.PostedFile.ContentType
Line 16: ImageStream = File1.PostedFile.InputStream

Source File: E:\hhsinternal\tests\sqlimage.aspx.vb Line: 14

Stack Trace:
[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions .ParseDecimal(String
Value, NumberFormatInfo NumberFormat) +193
Microsoft.VisualBasic.CompilerServices.Conversions .ToLong(String Value)
+72

[InvalidCastException: Conversion from string "image/x-png" to type 'Long'
is not valid.]
Microsoft.VisualBasic.CompilerServices.Conversions .ToLong(String Value)
+227
sqlimage.Button1_Click(Object sender, EventArgs e) in
E:\hhsinternal\tests\sqlimage.aspx.vb:14
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String
eventArgument) +78

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50215.44;
ASP.NET Version:2.0.50215.44

Here is my code:

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient

Partial Class sqlimage
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim intImageSize As Int64
Dim strImageType As String
Dim ImageStream As Stream

intImageSize = File1.PostedFile.ContentType
strImageType = File1.PostedFile.ContentType.ToString
ImageStream = File1.PostedFile.InputStream

Dim ImageContent(intImageSize) As Byte
Dim intStatus As Integer

intStatus = ImageStream.Read(ImageContent, 0, intImageSize)

Dim objConnection As SqlConnection
Dim objCommand As SqlCommand

objConnection = New
SqlConnection(ConfigurationManager.AppSettings("ap hrodite_test"))
objCommand = New SqlCommand("sp_addimage", objConnection)

objCommand.CommandType = CommandType.StoredProcedure

Dim InsertImage As New SqlParameter("@ImageFile", SqlDbType.Image)
InsertImage.Value = ImageContent
objCommand.Parameters.Add(InsertImage)

Dim InsertImageType As New SqlParameter("@ImageFileType",
SqlDbType.VarChar, 255)
InsertImageType.Value = strImageType
objCommand.Parameters.Add(InsertImageType)

Try

objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
Response.Write("Success")

Catch ex As Exception

Response.Write(ex.Message.ToString)

End Try
End Sub
End Class
This is my Stored Procedure on the sql box:

Create Proc sp_addimage
@ImageFile Image,
@ImageType varchar(255)
AS
BEGIN
INSERT INTO test.imagetest (photoimage, photoimagetype)
VALUES (@ImageFile, @ImageType)
END
GO
I have a database called test with a single table called imagetest with
three columns:

ID int IDENTITY,
photoimage image,
photoimagetype varchar(255)
Any help would be appreciated. If someone knows of an easier way to insert
an image into a sql 2000 table without using stored procedures, that'd be
great too! I only know how to use VB. C# would just leave me scratching my
head.

Thanks,
Jim

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben M. | last post by:
Greetings all, This should be an easy task, and Im sure it is, but as many times as I have tried, I cant seem to get this to work properly. We changed ISPs recently from a shared host to a...
2
by: hrishikesh musale | last post by:
hey does anybody know what are these in UDF's in SQL2k? when to use UDF's and when to use Stored procedures are they dependent? where i will get information on this topic please let me know...
0
by: pjrhoades | last post by:
Hi Group, I have a small development team developing using Interdev and ASP, we have just landed a project which would greatly benefit from dotNet, so are considering the implications of moving...
1
by: Warren | last post by:
Below is the script. The problem is when I simulated the Oracle link drop, my SQL2K never have to a chance to head to the GOTO section as it dies with this error msg and exit. Any idea on a...
1
by: Terrell Miller | last post by:
I have an Access front end with ODBC drivers to a SQL2k box. All our security is Wiondows-authentication on the back end, we don't use Access security workgroups. THerefore when I try to get the...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
by: holysmokes99 | last post by:
I get an error when I try to execute the following code using ADO.Net in VB.Net: conn.open sqlString="CREATE LOGIN test WITH PASSWORD = '1qaz2wsx'" command=new SqlCommand(sqlString)...
1
by: rsteph | last post by:
I've got some product information pages, with images and text, all setup within a table. I'm trying to add a small image in the upper right hand corner of the content div (where all the important...
0
by: lbseong | last post by:
Hi expect... I have ancounter another difficulty..I am getting an error message for replication "error 14294: supply either @job_id or @job_name to identify the job" This happen, after I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.