[英]Displaying image in reportviewer
I am trying to display images in a Report Viewer control in C# Widnows application. 我正在尝试在C#Widnows应用程序的Report Viewer控件中显示图像。 The image datasource is set as External.
图像数据源设置为“外部”。 If I have full path in the table field then it is working fine but If I have file name in the table field then I don't get the image.
如果我在table字段中具有完整路径,则可以正常工作,但是如果我在table字段中具有文件名,则无法获取图像。
File name only: deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp Full path: file:///C:\\MyApp\\Docs\\deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp 仅文件名:deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp完整路径:file:/// C:\\ MyApp \\ Docs \\ deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp
I am trying the follwoing code but not working with file name only. 我正在尝试下面的代码,但不能仅使用文件名。
<code>
string st = Application.StartupPath + @"\\Docs\";
cmd = new SqlCommand ("select " + st + "[fileName] as fileName from documents where id=Id", cn);
The file path has to be covered by single quote as it's a text in SQL syntax, so your code should be: 文件路径必须用单引号引起来,因为它是SQL语法中的文本,因此您的代码应为:
string st = System.IO.Path.Combine(Application.StartupPath, "Docs");
st = @"file:///" + st;
cmd = new SqlCommand ("select '" + st + "\\' + [fileName] as fileName from documents where id=Id", cn);
And check if your SQL statement is like this when debugging: 并在调试时检查您的SQL语句是否像这样:
select 'file:///D:\App\Admin\Admin\bin\Debug\Docs\' + [fileName] as fileName from documents where id=Id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.