Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.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# 在reportviewer中显示图像_C#_Asp.net_.net - Fatal编程技术网

C# 在reportviewer中显示图像

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 =

我试图在C#Widnows应用程序中的报表查看器控件中显示图像。图像数据源设置为外部。如果我在表字段中有完整路径,那么它可以正常工作,但是如果我在表字段中有文件名,那么我就无法获得图像

仅文件名: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