0
我使用下面的代碼來設置水晶報告&顯示的報告來源。我向該項目添加了一個DataSet &向該DataSet中添加了一個DataTable。 DataTable被命名爲「my_dt」& DataSet被命名爲「MyDataSet」。 「my_dt」DataTable恰好有3列以匹配我數據庫中的「考勤」表。當我按「開始調試」時,我沒有得到錯誤&它顯示一個空白報告。當我按「開始不調試」我得到這個錯誤。我不知道我做錯了什麼。請幫助我,任何幫助將不勝感激。加載Crystal Report時,爲什麼會出現「索引超出數組範圍」錯誤?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace CrystalReportWithAccess
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
my_rpt objRpt;
// Creating object of our report.
objRpt = new my_rpt();
String ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\CentreDB.mdb;Jet OLEDB:Database Password=pass";
OleDbConnection myConnection = new OleDbConnection(ConnStr);
String Query1 = "SELECT * FROM [Attendance]";
OleDbDataAdapter adapter = new OleDbDataAdapter(Query1, ConnStr);
DataSet Ds = new DataSet();
// here my_dt is the name of the DataTable which we
// created in the designer view.
adapter.Fill(Ds, "my_dt");
if (Ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("No data Found", "CrystalReportWithAccess");
return;
}
// Setting data source of our report object
objRpt.SetDataSource(Ds);
CrystalDecisions.CrystalReports.Engine.TextObject root;
root = (CrystalDecisions.CrystalReports.Engine.TextObject)
objRpt.ReportDefinition.ReportObjects["txt_header"];
root.Text = "Sample Report By Using Data Table!!";
// Binding the crystalReportViewer with our report object.
crystalReportViewer1.ReportSource = objRpt;
}
}
}
請原諒我的無知,但我必須添加使用指令來使用Ds.Tables.Length屬性?它說我錯過了一個參考。 – Ramila 2011-12-19 17:51:53
不,它應該使用'計數'而不是'長度' – Gabe 2011-12-19 17:53:37
好吧,我用它,但我仍然得到相同的錯誤? – Ramila 2011-12-19 17:54:36