Click here to Skip to main content
15,906,463 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Date Pin
pmarfleet7-Apr-08 10:28
pmarfleet7-Apr-08 10:28 
GeneralRe: Date Pin
biswa477-Apr-08 20:21
biswa477-Apr-08 20:21 
GeneralRe: Date Pin
Herman<T>.Instance8-Apr-08 4:40
Herman<T>.Instance8-Apr-08 4:40 
GeneralRe: Date Pin
pmarfleet8-Apr-08 11:07
pmarfleet8-Apr-08 11:07 
GeneralRe: Date Pin
Herman<T>.Instance8-Apr-08 23:40
Herman<T>.Instance8-Apr-08 23:40 
GeneralRe: Date Pin
pmarfleet9-Apr-08 9:23
pmarfleet9-Apr-08 9:23 
GeneralRe: Date Pin
pmarfleet8-Apr-08 11:05
pmarfleet8-Apr-08 11:05 
GeneralUploading Image to Server Pin
Paul McGann7-Apr-08 9:21
professionalPaul McGann7-Apr-08 9:21 
Hello

I'm having trouble uploading images to my sql express database. I have been searching endlessly to find a solution to my problem but to no-avail, I now turn to the trusted codeproject network for some help in solving the answer. I'm new to asp.net and am currently building an application to upload images into a database. I found the following tutorial()[^] and manipulated it to use a stored procedure. Below is the code in my code behind page:

Protected Sub btn_upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_upload.Click

Dim intLength As Integer
Dim arrContent As Byte()

If File_Upload.PostedFile Is Nothing Then
lbl_status.Text = "Please specify an image to upload"
Exit Sub
Else
Dim Filename As String = File_Upload.PostedFile.FileName
Dim ext As String = Filename.Substring(Filename.LastIndexOf("."))
ext = ext.ToLower

Dim image_type = File_Upload.PostedFile.ContentType
If ext = ".jpg" Then

ElseIf ext = ".bmp" Then

ElseIf ext = ".gif" Then

ElseIf ext = "jpg" Then

ElseIf ext = "bmp" Then

ElseIf ext = "gif" Then

Else

lbl_status.Text = "Only gif, bmp, or jpg format files supported."

Exit Sub

End If

intLength = Convert.ToInt32(File_Upload.PostedFile.InputStream.Length)

ReDim arrContent(intLength)
File_Upload.PostedFile.InputStream.Read(arrContent, 0, intLength)

If Upload_File_Server(txt_Image_Title.Text.Trim, arrContent, intLength, image_type) = True Then
lbl_status.Text = "Image uploaded successfully"
Else
lbl_status.Text = "An Error occurred while uploading please try again"
End If
End If
End Sub

Protected Function Upload_File_Server(ByVal title As String, ByVal Content As Byte(), ByVal Length As Integer, ByVal strType As String) As Boolean

Dim command As New SqlCommand("Upload_Article_Image")

conn.Open()
Try
command.CommandType = CommandType.StoredProcedure
command.Parameters.AddWithValue("@Content", Content)
command.Parameters.AddWithValue("@Title", title)
command.Parameters.AddWithValue("@Type", strType)
command.Parameters.AddWithValue("@Length", Length)
command.ExecuteNonQuery()

Return True

Catch ex As Exception

Return False

Finally

conn.Close()

End Try

End Function

The problem I am having is that the information is not being stored in the database and the function throws up the exception. If anyone can help me it would be greatfully appricated.

Regards
McGann
GeneralRe: Uploading Image to Server Pin
Christian Graus7-Apr-08 11:35
protectorChristian Graus7-Apr-08 11:35 
GeneralRe: Uploading Image to Server Pin
Paul McGann8-Apr-08 4:18
professionalPaul McGann8-Apr-08 4:18 
GeneralRe: Uploading Image to Server Pin
Ashish Sehajpal7-Apr-08 19:13
Ashish Sehajpal7-Apr-08 19:13 
GeneralDynamic table - Need help! Pin
humblepgmr7-Apr-08 5:29
humblepgmr7-Apr-08 5:29 
GeneralRe: Dynamic table - Need help! Pin
Mark J. Miller7-Apr-08 5:50
Mark J. Miller7-Apr-08 5:50 
Questionhow change a series in a chart using by asp.net Pin
Rinki Mukheraji7-Apr-08 4:55
Rinki Mukheraji7-Apr-08 4:55 
AnswerRe: how change a series in a chart using by asp.net Pin
Eduard Keilholz7-Apr-08 5:01
Eduard Keilholz7-Apr-08 5:01 
QuestionImplementing eBay API in ASP.NET Pin
wEb GuRu...7-Apr-08 4:23
wEb GuRu...7-Apr-08 4:23 
GeneralRe: Implementing eBay API in ASP.NET Pin
led mike7-Apr-08 4:41
led mike7-Apr-08 4:41 
QuestionRe: Implementing eBay API in ASP.NET Pin
wEb GuRu...7-Apr-08 6:21
wEb GuRu...7-Apr-08 6:21 
GeneralRe: Implementing eBay API in ASP.NET Pin
led mike7-Apr-08 7:08
led mike7-Apr-08 7:08 
QuestionPersist data Pin
LuKas23_7-Apr-08 4:04
LuKas23_7-Apr-08 4:04 
GeneralRe: Persist data Pin
led mike7-Apr-08 4:44
led mike7-Apr-08 4:44 
GeneralRe: Persist data Pin
LuKas23_7-Apr-08 5:49
LuKas23_7-Apr-08 5:49 
QuestionHow to access a cached objectdatasource data of a formview? Pin
JimFeng7-Apr-08 3:53
JimFeng7-Apr-08 3:53 
Generalregular validator Pin
eyeseetee7-Apr-08 3:43
eyeseetee7-Apr-08 3:43 
GeneralRe: regular validator Pin
eyeseetee7-Apr-08 4:31
eyeseetee7-Apr-08 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.