DataSet

Signaler
-
Messages postés
1137
Date d'inscription
lundi 17 novembre 2003
Statut
Membre
Dernière intervention
23 janvier 2016
-
Bonjour,
J ai une erreur que j ai du mal a trouver page_load . So j ai besoin daide please. voici le code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

public partial class TpDataBinding : System.Web.UI.Page
{
DataSet makeData()
{
DataSet mySet = new DataSet();

DataTable myTB = new DataTable("Players");
DataColumn myCol1 = new DataColumn();
myCol1.ColumnName = "RefTeam";
myCol1.DataType = typeof(Int32);

myTB.Columns.Add(myCol1);

DataColumn myCol2 = new DataColumn("PlayerName", typeof(String));
myTB.Columns.Add(myCol2);
myTB.Columns.Add(new DataColumn("Salary", typeof(float)));
myTB.Columns.Add(new DataColumn("Poste", typeof(String)));
myTB.Columns.Add(new DataColumn("Description", typeof(String)));

DataRow myRow = myTB.NewRow();
myRow = myTB.NewRow();
myRow["RefTeam"] = 3;
myRow["PlayerName"] = "Leonel Messi";
myRow["Salary"] = 7000000;
myRow["Poste"] = "Midfield";
myRow["Description"] = "Best";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 3;
myRow["PlayerName"] = "Piquet";
myRow["Salary"] = 4000000;
myRow["Poste"] = "Defense";
myRow["Description"] = "Tall";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 3;
myRow["PlayerName"] = " Cesc Fabregas";
myRow["Salary"] = 3500000;
myRow["Poste"] = "Forward";
myRow["Description"] = "Smart";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 3;
myRow["PlayerName"] = "Andreas Iniesta";
myRow["Salary"] = 4000000;
myRow["Poste"] = "Forward";
myRow["Description"] = "Smart";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 3;
myRow["PlayerName"] = "Neymar";
myRow["Salary"] = 6000000;
myRow["Poste"] = "Forward";
myRow["Description"] = "Smart";
myTB.Rows.Add(myRow);
// Barça
myRow = myTB.NewRow();
myRow["RefTeam"] = 1;
myRow["PlayerName"] = "Jamal Blackman";
myRow["Salary"] = 3000000;
myRow["Poste"] = "goalkeeper";
myRow["Description"] = "Tall";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 1;
myRow["PlayerName"] = "Gaël Kakuta";
myRow["Salary"] = 4600000;
myRow["Poste"] = "Forward";
myRow["Description"] = "Tall";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 1;
myRow["PlayerName"] = "Demba Ba";
myRow["Salary"] = 5440000;
myRow["Poste"] = "Forward";
myRow["Description"] = "Smart";
myTB.Rows.Add(myRow);
//Chealse

myRow = myTB.NewRow();
myRow["RefTeam"] = 2;
myRow["PlayerName"] = "Camara Zoumana";
myRow["Salary"] = 1600000;
myRow["Poste"] = "Defender";
myRow["Description"] = "Tall";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 2;
myRow["PlayerName"] = "Kabaye Yohan";
myRow["Salary"] = 2000000;
myRow["Poste"] = "Midfield";
myRow["Description"] = "Smart";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 2;
myRow["PlayerName"] = "Ibrahimovic Zlatan";
myRow["Salary"] = 5440000;
myRow["Poste"] = "Forward";
myRow["Description"] = "Best";
myTB.Rows.Add(myRow);
//Paris Saint germain

myRow = myTB.NewRow();
myRow["RefTeam"] = 4;
myRow["PlayerName"] = "Mario Balotelli";
myRow["Salary"] = 7000000;
myRow["Poste"] = "Forward";
myRow["Description"] = "Fast";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] =4;
myRow["PlayerName"] = "Robinho";
myRow["Salary"] = 8000000;
myRow["Poste"] = "Forward";
myRow["Description"] = "Fast";
myTB.Rows.Add(myRow);

myRow = myTB.NewRow();
myRow["RefTeam"] = 4;
myRow["PlayerName"] = "Christian Abiatti";
myRow["Salary"] = 6100000;
myRow["Poste"] = "goalkeeper";
myRow["Description"] = "Tall";
myTB.Rows.Add(myRow);
//Milan AC
// table Players

DataTable myTB1 = new DataTable("Teams");
DataColumn myCol = new DataColumn();

myCol.ColumnName = "RefTeam";
myCol.DataType = typeof(Int32);
myTB1.Columns.Add(myCol);

DataColumn myCol9 = new DataColumn("teamName", typeof(String));
myTB1.Columns.Add(myCol9);

DataRow myRow1 = myTB1.NewRow();
myRow1 = myTB1.NewRow();
myRow1["RefTeam"] = 3;
myRow1["teamName"] = "Barcelone";
myTB1.Rows.Add(myRow1);

myRow1 = myTB1.NewRow();
myRow1["RefTeam"] = 1;
myRow1["teamName"] = "Clealse";
myTB1.Rows.Add(myRow1);

myRow1 = myTB1.NewRow();
myRow1["RefTeam"] = 2;
myRow1["teamName"] = "PSG";
myTB1.Rows.Add(myRow1);

myRow1 = myTB1.NewRow();
myRow1["RefTeam"] = 4;
myRow1["teamName"] = "Milan";
myTB1.Rows.Add(myRow1);
//Table Teams

return mySet;

}//Fin DataSet

protected void Page_Load(object sender, EventArgs e)
{
DataSet mySetSoccer = makeData();
DataTable TBteams = mySetSoccer.Tables["Teams"];
DataTable TBPlayers = mySetSoccer.Tables["Players"];

if (!IsPostBack)
{
cboTeam.DataValueField = "RefTeam";
//cboSortBy.DataTextField = "RefTeam";
cboSortBy.DataSource = TBteams.Columns; // erreur est ici??????
cboSortBy.DataBind();
}

DataView myview = new DataView(TBPlayers);
myview.Sort = cboSortBy.SelectedItem.Text + "ASC";
myview.RowFilter = "RefTeam = " + cboTeam.SelectedItem.Value;

GridView1.DataSource = myview;
GridView1.DataBind();

DataView myView2 = new DataView(TBteams);
GridView2.DataSource = myView2;
GridView2.DataBind();

}
protected void cboSortBy_SelectedIndexChanged(object sender, EventArgs e)
{

}
}

1 réponse

Messages postés
1137
Date d'inscription
lundi 17 novembre 2003
Statut
Membre
Dernière intervention
23 janvier 2016
20
Salut,

tu ne valides pas la modif de structure des tables
et tu n'ajoutes pas tes tables au DataSet

Rajoutes ceci a la fin de makeData (avant le return)

DataSet  makeData
{
    // bla bla

    myTB.AcceptChanges();
    myTB1.AcceptChanges();

    mySet.Tables.Add( myTB  );
    mySet.Tables.Add( myTB1  );

    return mySet ;
}


bye...