how to retrieve an image from database using image URL and insert it in grid view in vb. net ??
thats my data base table
i have 3 columns in table image (ID as int , imageName as varchar , imageURL as varchar(max) i want to insert the image in a grid view but when i run this code i only get the last image in my table everytime
thats my code:
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"
D开发者_StackOverflow社区im 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
you should have this column in the column definition of your GridView:
<asp:ImageField DataImageUrlField="PictureURL"></asp:ImageField>
where PictureURL is the name of the column which contains the image url.
here there is a full example directly from MSDN:
Displaying Images in a GridView Column
精彩评论