private bool _isReportViewerLoaded;
private void reportViewer_Load(object sender, EventArgs e)
{
if (!_isReportViewerLoaded)
{
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
SellMechDataSet dataset = new SellMechDataSet();
dataset.BeginInit();
reportDataSource1.Name = "DataSet2";
//Name of the report dataset in our .RDLC file
reportDataSource1.Value = dataset.tblLogo;
this.reportViewer.LocalReport.DataSources.Add(reportDataSource1);
this.reportViewer.LocalReport.ReportPath = "D:\\17-6-2016\\ShellMechProject\\demo\\Reports\\CustomerList.rdlc ";
dataset.EndInit();
//fill data into WpfApplication4DataSet
SellMechDataSetTableAdapters.tblLogoTableAdapter accountsTableAdapter = new SellMechDataSetTableAdapters.tblLogoTableAdapter();
accountsTableAdapter.ClearBeforeFill = true;
accountsTableAdapter.Fill(dataset.tblLogo);
string ImagePath = "";
if (con.State != ConnectionState.Open)
con.Open();
{
SqlCommand cmd = new SqlCommand("SELECT * FROM tblLogo", con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
ImagePath = dr["ImagePath"].ToString();
}
}
ReportParameter rp = new ReportParameter("Path", ImagePath);
rp.Name = "Path";
//rp.Values = ImagePath;
reportViewer.LocalReport.SetParameters(new ReportParameter[] { rp });
reportViewer.RefreshReport();
_isReportViewerLoaded = true;
}
}
設計:
<Window x:Class="demo.Reports.CustomerList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
Icon="/img\F_Logo.png"
WindowStyle="None"
ShowInTaskbar="False"
Title="Customer Report" Height="742.955" Width="1140.164" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" Loaded="Window_Loaded">
<Grid Margin="-1,2,1,-172" Background="#d9f9f7" Height="913" VerticalAlignment="Top">
<Label Content="Customer Report" VerticalAlignment="Top" Height="25" HorizontalContentAlignment="Center" Background="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}" Margin="-1,-2,0.2,0"></Label>
<Button Content="X" Name="btnExit" Grid.Row="0" Height="20" Width="20" FontFamily="Times New Roman" Foreground="Red" FontWeight="Bold" FontSize="18" Margin="1118,0,2,893" RenderTransformOrigin="4.564,0.572" Click="btnExit_Click" />
<Grid Margin="0,23,0,-23">
<WindowsFormsHost Name="windowsFormsHost1">
<rv:ReportViewer x:Name="reportViewer" Load="reportViewer_Load" />
</WindowsFormsHost>
</Grid>
</Grid>
</Window>
我從數據庫中獲取路徑,將其顯示爲圖像控制 但錯誤發生
本地報告處理期間發生錯誤。
如果在wpf report logo中有任何其他選項可用。
我想從數據庫 – rani
圖像與所述數據從數據庫改變到代碼'的ImagePath =博士[ 「的ImagePath」]的ToString();'不應該這個困難。您正在從路徑中加載文件,並使用從數據庫中提供的路徑。在我的例子中,路徑在代碼中被修復。那麼適應這個問題有什麼問題?我的建議是不要爲報告指定路徑。只需將它加載到字節數組並將字節數組分配給報告字段即可。 – MarkusEgle
好吧,我會嘗試... – rani