Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检索存储在sql server 2005中的映像时出现问题_C#_Asp.net_Sql Server 2005 - Fatal编程技术网

C# 检索存储在sql server 2005中的映像时出现问题

C# 检索存储在sql server 2005中的映像时出现问题,c#,asp.net,sql-server-2005,C#,Asp.net,Sql Server 2005,我正在尝试使用c#将图像从sql server 2005检索到asp.net网页,下面是我的代码 SqlCommand getImageCmd = new SqlCommand("select Image from Images where ImageName = '" + getImageDropDownList.SelectedValue.ToString() + "'", con); byte[] imageData = (byte[])getImageCmd.ExecuteScalar(

我正在尝试使用c#将图像从sql server 2005检索到asp.net网页,下面是我的代码

SqlCommand getImageCmd = new SqlCommand("select Image from Images where ImageName = '" + getImageDropDownList.SelectedValue.ToString() + "'", con);
byte[] imageData = (byte[])getImageCmd.ExecuteScalar();

FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);

fs.Write(imageData, 0, (imageData.Length) );

Image1.ImageUrl = "path";
fs.Close();
问题是我的图像控件中没有任何输出

以下是我用于将图像存储到数据库中的代码: byte[]data=ImageUpload.FileBytes

SqlCommand sc = new SqlCommand("insert into Images(ImageName,Image) values (@n, @p)", con);
sc.Parameters.AddWithValue("@p", data);
sc.Parameters.AddWithValue("@n", imageNameTextBox.Text);
sc.ExecuteNonQuery();
试试看这里:


我想你想做的是

  • 从数据库中抓取图像
  • 保存在磁盘上和
  • 设置该文件的URL
  • 发布的代码唯一明显错误的地方是将
    ImageUrl
    设置为literal
    “Path”
    而不是Path中存储的值。很明显,Path不是URL,而是一个目录/文件路径,因此您需要使用一些技巧将其设置为URL

    如果您不反对使用其他人的代码,并且能够这样做,我将对此进行检查 -,它很有效,非常棒


    如果所有其他的都失败了,请考虑编写自己的ASHX或IHTHPHANDANER的实现来解决这个问题。一个快速的谷歌出现了这个

    发布的代码就是有问题的代码吗?您似乎在filestream构造函数中获得了一个伪“值”。在filestream构造函数中获得了一个伪“值”??我没有理解您!!filestream fs=new filestream(“路径-应该是filestream fs=new filestream(路径)?path是存储目标文件路径的字符串,如果这是您的问题的话。