[英]Displaying image in reportviewer
我正在尝试在C#Widnows应用程序的Report Viewer控件中显示图像。 图像数据源设置为“外部”。 如果我在table字段中具有完整路径,则可以正常工作,但是如果我在table字段中具有文件名,则无法获取图像。
仅文件名:deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp完整路径:file:/// C:\\ MyApp \\ Docs \\ deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp
我正在尝试下面的代码,但不能仅使用文件名。
<code>
string st = Application.StartupPath + @"\\Docs\";
cmd = new SqlCommand ("select " + st + "[fileName] as fileName from documents where id=Id", cn);
文件路径必须用单引号引起来,因为它是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);
并在调试时检查您的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.