Hi i hope someone maybe able to help me as i've been trying all sorts of things to get this to work for days now...your my last resort.
i have a gridview that displays picture that are uploaded by users...my problem if a user uploads a picture. it won't show in the gridview displaying it...i've tried databinding it at all stages of the code but it doesn't seem to help..also if you go back to the home page then back to the update screen it still won't show the new pics...you have to log right out of asp and reload the complete site to be able to see the new pictures?
Dim strImageName As String = txtName.Text.ToString()
If FileUpload1.PostedFile IsNot Nothing AndAlso FileUpload1.PostedFile.FileName <> "" Then
Dim imageSize As Byte() = New Byte(FileUpload1.PostedFile.ContentLength - 1) {}
Dim uploadedImage__1 As HttpPostedFile = FileUpload1.PostedFile()
uploadedImage__1.InputStream.Read(imageSize, 0, CInt(FileUpload1.PostedFile.ContentLength))
Dim con As New Data.SqlClient.SqlConnection()
con.ConnectionString = ConfigurationManager.ConnectionStrings()("ConnectionString").ConnectionString
' Create SQL Command
Dim cmd As New Data.SqlClient.SqlCommand()
cmd.CommandText = "INSERT INTO Images (ImageName,Image,userid) VALUES (@ImageName,@Image,@userid)"
cmd.CommandType = Data.CommandType.Text
cmd.Connection = con
Dim ImageName As New Data.SqlClient.SqlParameter("@ImageName", Data.SqlDbType.VarChar, 50)
ImageName.Value = strImageName.ToString()
cmd.Parameters.Add(ImageName)
Dim struserid As String = lblid.Text.ToString()
Dim userid As New Data.SqlClient.SqlParameter("@userid", Data.SqlDbType.VarChar, 50)
userid.Value = struserid.ToString()
cmd.Parameters.Add(userid)
Dim UploadedImage__2 As New Data.SqlClient.SqlParameter("@Image", Data.SqlDbType.Image, imageSize.Length)
UploadedImage__2.Value = imageSize
cmd.Parameters.Add(UploadedImage__2)
con.Open()
Dim result As Integer = cmd.ExecuteNonQuery()
con.Close()
If result > 0 Then
lblMessage.Text = "File Uploaded"
End If
End If
txtName.Text = ""
recordcount()
End Sub
this is the upload code i am using that sees to work really well. just the gridview thats the problem....oh also if i delete a picture on this screen using asp code it updates the gridview fine and then will display all the new uploaded pictures?
many thanks andy