C# 使用不带处理程序的webservice从SQLSERVER数据库检索图像?

C# 使用不带处理程序的webservice从SQLSERVER数据库检索图像?,c#,asp.net,sql-server,web-services,asmx,C#,Asp.net,Sql Server,Web Services,Asmx,我想知道是否有任何方法可以在不使用web服务[Asp.net]中的处理程序的情况下从SqlServer检索图像 我目前正在使用此代码 在我的webservice.cs文件中 在我使用/消费web服务的示例网站中,我使用的代码是default.aspx.cs文件中的代码 public partial class _Default : System.Web.UI.Page { xyz.WebService obj = new xyz.WebService(); protected

我想知道是否有任何方法可以在不使用web服务[Asp.net]中的处理程序的情况下从SqlServer检索图像

我目前正在使用此代码

在我的webservice.cs文件中
在我使用/消费web服务的示例网站中,我使用的代码是default.aspx.cs文件中的代码

public partial class _Default : System.Web.UI.Page
{
    xyz.WebService obj = new xyz.WebService();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Int32 In = FileUpload1.PostedFile.ContentLength;
        Byte[] ar = new Byte[In];
        FileStream fs = new FileStream(FileUpload1.PostedFile.FileName, FileMode.Open, FileAccess.ReadWrite);
        fs.Read(ar, 0, In - 1);
        fs.Close();
        obj.Save_Image(Convert.ToInt32(TextBox1.Text), ar);
        TextBox1.Text = string.Empty;
        TextBox1.Focus();


    }
   protected void Button2_Click(object sender, EventArgs e)
    {
        Byte[] ar = obj.Ret_Image(Convert.ToInt32(TextBox3.Text));
        string st = Server.MapPath("ar"); 
        FileStream fs = new FileStream(st, FileMode.Create, FileAccess.Write);
        fs.Write(ar, 0, ar.Length - 1);
        fs.Close();
        Image1.ImageUrl = st;
    }
}
根据我的说法,这行[string st=Server.MapPath(“ar”);]在受保护的void按钮2_单击(object sender,EventArgs e)应该更改,但我不知道必须使用哪个命令


下面的代码是default.aspx文件的设计**

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>Image Id:</td>
    <td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
    <td>Image Path:</td>
    <td><asp:FileUpload ID="FileUpload1" runat="server" /> </td>
    </tr>
    <tr><td colspan="2" align="center"><asp:Button ID ="Button1" runat="server" 
            Text="Upload" onclick="Button1_Click" /></td></tr>
    </table>
    <table>
    <tr><td> Enter Image ID </td>
    <td><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td></tr>
    <tr><td colspan="2" align="center"><asp:Button ID="Button2" runat="server" 
            onclick="Button2_Click" Text="Retrieve Image" /></td></tr>
    </table>
        <br />
        <br />
        <asp:Image ID="Image1" runat="server" />
    </div>
    </form>
</body>
</html>

图像Id:
图像路径:
输入图像ID



数据库表名为tbimages

有两列的

  • imageid[数据类型-Int]
  • 2.imagename[数据类型--图像]
    这是我的第一篇文章,如果我有任何错误,也请提及。

    您可以随时将图像路径/url保存在数据库中,并在以后需要时检索它。将图像url放在html源标记中。请参考以下示例:

    <img src="<% image url %>"></img>
    
    “>
    

    希望这有帮助!

    我不确定您到底面临着什么问题。您能添加更多详细信息吗?我无法从数据库检索图像,如果添加断点,我会在图像控制中看到null路径传递,我将如何获取Url?因为我将图像保存在数据库中,而不是文件系统中。
    <img src="<% image url %>"></img>