Can some one help me how to to display images from my database, this is my code

asp.net , db Indore, India
  • 12 years ago

    Imports System

    Imports System.Data

    Imports System.Configuration

    Imports System.Collections

    Imports System.Web

    Imports System.Web.Security

    Imports System.Web.UI

    Imports System.Web.UI.WebControls

    Imports System.Web.UI.WebControls.WebParts

    Imports System.Web.UI.HtmlControls

    Imports System.Data.SqlClient

    Partial Public Class Code_DatabaseBased_AddProduct

    Inherits System.Web.UI.Page

    Protected Sub AddImageButton_Click(ByVal sender As Object, ByVal e As EventArgs)

    If Not Page.IsValid Then

    Return

    End If

    ' If a file was uploaded...

    If ImageUpload.HasFile Then

    ' Add a new record to the database table PicturesFS

    Const sql As String = "INSERT INTO ProductUpload(CategoryID, ProductTitle, ImageData, ContentType) VALUES(@CategoryID, @ProductTitle, @ImageData, @" & _

    "ContentType)"

    Dim myConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("CustomerConnectionString6").ConnectionString)

    myConnection.Open()

    Dim myCommand As SqlCommand = New SqlCommand(sql, myConnection)

    ' Assign the parameter values

    myCommand.Parameters.AddWithValue("@CategoryID", Convert.ToInt32(Products.SelectedValue))

    myCommand.Parameters.AddWithValue("@ProductTitle", ImageTitle.Text.Trim)

    myCommand.Parameters.AddWithValue("@ImageData", ImageUpload.FileBytes)

    myCommand.Parameters.AddWithValue("@ContentType", ImageUpload.PostedFile.ContentType)

    ' Execute the INSERT

    myCommand.ExecuteNonQuery()

    ' Redirect the user to Default.aspx

    Response.Redirect("Default.aspx")

    End If

    End Sub

    Protected Sub CancelButton_Click(ByVal sender As Object, ByVal e As EventArgs)

    ' Send the user back to Default.aspx

    Response.Redirect("Default.aspx")

    End Sub

    End Class

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Weeks of coding can save you hours of planning.”