Я все время получаю ошибку не могу найти таблицу 0
DataSet ds = new DataSet(); DataRow[] result = ds.Tables[0].Select("Team = '" + listBox1.SelectedItem + "'"); // filter result set DataTable dtPlayerInfo = new DataTable(); dtPlayerInfo = result.CopyToDataTable(); DataTable dtCloned = dtPlayerInfo.Clone(); dtCloned.Columns[3].DataType = typeof(double); dtCloned.Columns[2].DataType = typeof(double); foreach (DataRow row in dtPlayerInfo.Rows) { dtCloned.ImportRow(row); } // Avg hit of team double hitsAvg = dtCloned.AsEnumerable() .Average(r => r.Field<double>("hits")); // Avg bat of team double atBatAvg = dtCloned.AsEnumerable() .Average(r => r.Field<double>("atBats")); // Actual Avg of team double teamAvg = hitsAvg / atBatAvg; DataTable dtPlayerAvg = new DataTable(); DataRow rowPlayer = dtPlayerAvg.NewRow(); dtPlayerAvg.Columns.Add("Player", typeof(string)); dtPlayerAvg.Columns.Add("Batteing Avg", typeof(double)); for (int i = 0; i < dtCloned.Rows.Count; i++) ; { double AvgPayer = Convert.ToDouble(dtCloned.Rows[3]) / Convert.ToDouble(dtCloned.Rows[2]); if (teamAvg <= AvgPayer) ; // checked palyer Avg to Team Avg { dtPlayerAvg.Rows.Add(dtCloned.Rows[0].ToString(), Math.Round(AvgPayer, 4)); } } DataView view = dtPlayerAvg.DefaultView; view.Sort = "Batteing Avg DESC "; //This cannot be done with the original data table. so created a new, sorted one: DataTable sortedDate = view.ToTable(); dataGridView1.DataSource = sortedDate;
Что я уже пробовал:
Я перепробовал все, но до сих пор не работает
PIEBALDconsult
DataSet ds = новый набор данных();
DataRow[] result = ds.Tables[0] <==== в новом наборе данных нет таблиц.