【问题标题】:Show specific set of fields显示特定的字段集
【发布时间】:2018-02-27 08:41:39
【问题描述】:

我正在尝试显示一组特定的字段,从 SQL 中提取到我的水晶报表中。

SqlConnection cnn;
string connectionString = null;
string sql = null;

connectionString = "Data Source=RHYME-PC\\SQLEXPRESS;Initial Catalog=Caproj;Integrated Security=True;";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select DriverID, FirstName, MiddleName, LastName, ContactNo, EmergencyNumber, Address, Documents, Status, ContactPerson, BirthDate, YearsOfExperience from [Driver Table]";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
DataSet ds = new DataSet();
dscmd.Fill(ds, "[Driver Table]");
MessageBox.Show(ds.Tables[6].Rows.Count.ToString());
cnn.Close();

DriverReport rpt = new DriverReport();
rpt.SetDataSource(ds.Tables[6]);
crystalReportViewer1.ReportSource = rpt;
crystalReportViewer1.Refresh();

我在"MessageBox.Show(ds.Tables[6].Rows.Count.ToString());" 行中收到一个错误,上面写着,

“System.IndexOutOfRangeException”类型的未处理异常 发生在 System.Data.dll

附加信息:找不到表 6。

我该如何解决这个问题?

【问题讨论】:

    标签: c# sql-server visual-studio crystal-reports


    【解决方案1】:

    你的数据集中只有一张表,所以你想把 6 改成 0

    MessageBox.Show(ds.Tables[0].Rows.Count.ToString());
    

    我想这会解决你的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-27
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-28
      相关资源
      最近更新 更多