从文件夹和数据库中读取图像

时间:2013-12-25 13:15:27

标签: asp.net sql-server vb.net

如何使用asp.net vb代码从数据库“images”和她的名字中读取图像 这是我使用的代码。

   Dim conn As SqlConnection
   Dim cmd As SqlCommand
   Dim cmdString As String = ("select TOP 20 * from tbl_news order by db_id desc ")
   conn = New SqlConnection("Data Source=.\sqlexpress;AttachDbFilename=C:\Users\m7md\Documents\Visual Studio 2008\Projects\AlAkhbar\AlAkhbar\App_Data\Database1.mdf;Integrated Security=True;User Instance=True")
   cmd = New SqlCommand(cmdString, conn)
   conn.Open()
   Dim dr As SqlDataReader = cmd.ExecuteReader

   While (dr.Read)
       Response.Write("<div id=title>")
       Response.Write("<img src='images/db_img')  />")
       Response.Write("</div>")
       Response.Write("<div id=title>")
       Response.Write(dr("db_title"))
       Response.Write("<br/>")
       Response.Write("<br/>")
       Response.Write("</div>")
       Response.Write("<div id=sumury>")
       Response.Write(dr("db_sumury"))
       Response.Write("</div>")
       Response.Write("<div id=readmore>")
       Response.Write("<a href=readmore.aspx?id=" & dr("db_id").ToString & "> Readmore</a>")
       Response.Write("</div>")
       Response.Write("<hr/>")

   End While