Hi
Ich habe eine Frage, kann ich einen Report.rdlc direkt ausdrucken, ohne den vorher zu öffnen?
Unter gotreportviewer.com gibt es ein Beispiel, aber da werden mir die Daten aus einem XML gelesen und dann umgewandelt.
Gibt es da noch einen einfacheren Weg? Ich habe das versucht, aber bei mir klappt das irgendwie nicht mit dem Beispiel von gotreportviewer.com, da bekomme ich immer eine leere Seite.
Ich arbeite mit VS 2005 und meine Daten kommen aus einer MySQL DB.
Hier ein Codeausschnitt von mir:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
| private void cmd_Button_Click(object sender, EventArgs e) { if (Globals.mycon.State == ConnectionState.Closed) { Globals.mycon.Open(); } MySqlDataAdapter MyAdapterTabelle1 = new MySqlDataAdapter("SELECT * FROM tabelle1;", Globals.mycon); MySqlDataAdapter MyAdapterTabelle2 = new MySqlDataAdapter("SELECT * FROM tabelle2;", Globals.mycon);
MyAdapterTabelle1 .Fill(dataSet.Tables["tabelle1"]); MyAdapterTabelle2.Fill(dataSet.Tables["tabelle2"]);
LocalReport report = new LocalReport(); report.ReportPath = @"..\..\report.rdlc"; report.DataSources.Add(new ReportDataSource("dataSet", dataSet.Tables["tabelle1"])); report.DataSources.Add(new ReportDataSource("dataSet", dataSet.Tables["tabelle2"]));
Export(report); Print();
if (Globals.mycon.State == ConnectionState.Open) { Globals.mycon.Close(); Globals.mycon.Dispose(); } }
private void Export(LocalReport report) { string deviceInfo = "<DeviceInfo>" + " <OutputFormat>EMF</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.25in</MarginTop>" + " <MarginLeft>0.25in</MarginLeft>" + " <MarginRight>0.25in</MarginRight>" + " <MarginBottom>0.25in</MarginBottom>" + "</DeviceInfo>";
Warning[] warnings; m_streams = new List<Stream>();
try { report.Render("Image", deviceInfo, CreateStream, out warnings);
foreach (Stream stream in m_streams) { stream.Position = 0; } } catch (Exception exp) { Exception innerExp = exp.InnerException; while (innerExp.InnerException != null) { innerExp = innerExp.InnerException; }
if (innerExp != null) { MessageBox.Show(innerExp.Message, exp.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show(exp.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek) { Stream stream = new FileStream(@"..\..\" + name + "." + fileNameExtension, FileMode.Create); m_streams.Add(stream); return stream; } |
Ich bekomme folgende Fehlermeldung.
"Für die DataSet-Datenquelle wurde keine Datenquelleninstanz bereitgestellt."
Kann mir jemand sagen was ich falsch mache. fröhlich Ein Beispiel würde mir weiterhelfen.
Gruß Doommortar