C# 在reportviewer中显示图像
我试图在C#Widnows应用程序中的报表查看器控件中显示图像。图像数据源设置为外部。如果我在表字段中有完整路径,那么它可以正常工作,但是如果我在表字段中有文件名,那么我就无法获得图像 仅文件名:deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp完整路径:file:///C:\MyApp\Docs\deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp 我正在尝试以下代码,但不使用文件名C# 在reportviewer中显示图像,c#,asp.net,.net,C#,Asp.net,.net,我试图在C#Widnows应用程序中的报表查看器控件中显示图像。图像数据源设置为外部。如果我在表字段中有完整路径,那么它可以正常工作,但是如果我在表字段中有文件名,那么我就无法获得图像 仅文件名:deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp完整路径:file:///C:\MyApp\Docs\deef2d72-e75a-41d4-8acd-086f7fe6aa89.bmp 我正在尝试以下代码,但不使用文件名 <code> string st =
<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