使用VB.NET 3.5从SQL Server2005检索DataGrid中的图像 [英] Retrive Image in DataGrid from sql server2005 USING VB.NET 3.5

查看:74
本文介绍了使用VB.NET 3.5从SQL Server2005检索DataGrid中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,所有专家,我都成功检索了除图像数据以外的所有数据,我无法找到我的错,所以请帮助我改善答案,我的代码如下:-

代码如下:-----

Hi All expert , i retrive all data sucessfully except image data , i could not be able to find my fault so please help me in improve my answer my code is as below :-

CODE BEHIND :-----

Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class Default2
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindGrid()
        End If
    End Sub
    Private Sub BindGrid()
        '' Create Instance of Connection and Command Object
        Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
        Dim myCommand As SqlCommand = New SqlCommand("sp_das_person_real_images_sel", myConnection)
        '' Mark the Command as a SPROC
        myCommand.CommandType = CommandType.StoredProcedure
        Try
            myConnection.Open()
            DG_Persons.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
            DG_Persons.DataBind()
        Catch SQLexc As SqlException
            Response.Write("Error occured while Generating Data. Error is " & SQLexc.ToString())
        End Try

    End Sub
    Function FormatURL(ByVal strArgument As String) As String
        Return ("readrealimage.aspx?id=" & strArgument)
    End Function
End Class



源代码:------



SOURCE CODE :------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title>Untitled Page</title>

</head>

<body style="font: 10pt verdana">



从SqlServer检索图像并在DataGrid中显示.





Retrieving images from SqlServer and Displaying in the DataGrid.



 <form id="Form1" method="post"  runat="server">

  <asp:DataGrid ID="DG_Persons" AutoGenerateColumns="false"  Width="99%" HeaderStyle-BackColor="#ff0000" HeaderStyle-Font-Bold="True"
     HeaderStyle-Font-Name="Verdana" HeaderStyle-Font-Size="13px" HeaderStyle-ForeColor="#ffffff" ItemStyle-BackColor="Beige"
     ItemStyle-Font-Name="verdana" ItemStyle-Font-Size="13px" BorderColor="#000000" Runat="server">
<columns>
   <asp:TemplateColumn HeaderText="Name">
        <itemtemplate>
           <asp:Label ID="Label1" Runat="server" Text=''<%# DataBinder.Eval(Container.DataItem, "PersonName") %>''/> </itemtemplate>
   
   <asp:TemplateColumn HeaderText="Email">
       <itemtemplate>
           <asp:Label ID="Label2" Runat="server" Text=''<%#DataBinder.Eval(Container.DataItem, "PersonEmail") %>''/>
       </itemtemplate>
   
   <asp:TemplateColumn HeaderText="Sex">
        <itemtemplate>
             <asp:Label ID="Label3" Runat="server" Text=''<%# DataBinder.Eval(Container.DataItem,"PersonSex") %>'' />
        </itemtemplate>
   
   <asp:TemplateColumn HeaderText="Date of Birth">
        <itemtemplate>
         <asp:Label ID="Label4" Runat="server" Text=''<%# DataBinder.Eval(Container.DataItem,"PersonDOB") %>''/>
        </itemtemplate>
   
   <asp:TemplateColumn HeaderText="Image">
        <itemtemplate>
             <asp:Image ID="Image1" Width="250" Height="225" ImageUrl=''<%# FormatURL(DataBinder.Eval(Container.DataItem,"PersonID").ToString) %>''  Runat="server">
        </itemtemplate>
   
</columns>

    </form>

  </body>

</html>

推荐答案

您需要一个单独的页面,该页面带有图像ID,并返回带有正确标题的图像字节.然后,您需要为指向该页面的图像构建一个URL,并传入ID,以便它读取正确的图像. google上的大量信息.
You need a seperate page which takes an image ID and returns the bytes of the image with the right header. Then you need to build a URL for the image that points to that page, passing in the ID so it reads the right image. Tons of info on google on this.


这篇关于使用VB.NET 3.5从SQL Server2005检索DataGrid中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆