how to retrieve an image url from DB and insert it in grid view! ASAP

Discussion in 'ASP.NET / ASP.NET Core' started by kaz89, Sep 3, 2011.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. hi i have this table DB

    image(ID as integer,imageName as varchar (50), imageURL as varchar (max)

    and i want to insert the values in a grid view when i run my code it get the values from the FB except that it only get the last image from DB

    thats my code

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "false"

    Font-Names = "Arial"
    style="z-index: 1; left: 8px; top: 167px; position: absolute; height: 374px; width: 369px" >

    <Columns>

    <asp:BoundField DataField = "ID" HeaderText = "ID" />

    <asp:BoundField DataField = "FileName" HeaderText = "Image Name" />

    <asp:ImageField DataImageUrlField="FilePath" ControlStyle-Width="100"ControlStyle-Height = "100" HeaderText = "Preview Image"/>

    </Columns>

    </asp:GridView>





    -------------------------------------------------------------------------------------------------------------------------------



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    '---------------------------------------------------------------------------

    Dim dt As New DataTable()

    Dim strConnString As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString()

    Dim strQuery As String = "select * from image"

    Dim con As New SqlConnection(strConnString)

    Dim cmd As New SqlCommand(strQuery, con)

    Dim sda As New SqlDataAdapter()

    cmd.CommandType = CommandType.Text

    cmd.Connection = con

    Try

    con.Open()

    sda.SelectCommand = cmd

    sda.Fill(dt)


    GridView1.DataSource = dt

    GridView1.DataBind()




    Catch ex As Exception

    Response.Write(ex.Message)

    Finally

    con.Close()

    sda.Dispose()

    con.Dispose()

    End Try


    End Sub


    please reply ASAP
     
  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    The data doesn't appear to bound in your ImageField.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page