Transac SQL

philo71 Messages postés 28 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 10 mars 2008 - 5 août 2005 à 18:28
cs_coq Messages postés 6350 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 - 5 août 2005 à 19:03
Bonjour,
Je suis entrain de développer une application transac SQL sur sql serveur en C#,
apres l'appel d'un proc stock (procédure stockée) , le programme rempli bien mon grid.
mais je veut pouvoir parcourir la table mannuellement avec des textbox pour afficher
l'information .
et comme par hasard le workspace me retourne une erreur !!

voici le code sans erreur :


// affichage select //



try


{
SqlConnection northwindConnection =
new SqlConnection(connectionString);
SqlCommand cmd =
new SqlCommand("affiche_article", northwindConnection);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da=
new SqlDataAdapter(cmd);
DataSet dsSeafood=
new DataSet();
da.Fill(dsSeafood, "Seafood");
dgSeafood.DataSource = dsSeafood.Tables[0];
max_i = dsSeafood.Tables["Seafood"].Rows.Count;

this.textBox11.Text = max_i.ToString();
i = 0;

this.textBox6.Text = dsSeafood.Tables[0].Rows[0].ItemArray[0].ToString();

this.textBox7.Text = dsSeafood.Tables[0].Rows[0].ItemArray[1].ToString();

this.textBox8.Text = dsSeafood.Tables[0].Rows[0].ItemArray[2].ToString();

this.textBox9.Text = dsSeafood.Tables[0].Rows[0].ItemArray[3].ToString();

this.textBox10.Text = dsSeafood.Tables[0].Rows[0].ItemArray[4].ToString();

/////////////////////
}

catch (SqlException sqlExc)
{
MessageBox.Show(sqlExc.ToString(), "SQL Exception Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Jusqu'ici il n'y a pas d'erreur, l'appel de la proc stock marche bien
par contre pour parcourir manuellement ma table j'ai l'erreur donc je vous parle.



private
void button6_Click(
object sender, System.EventArgs e)
{

// parcourt champs suivant
if (i < max_i )
i = i + 1;

this.textBox11.Text = i.ToString();

if ( i < max_i )
{
//-l'erreur est ici*
this.textBox6.Text = dsSeafood.Tables[0].Rows[i].ItemArray[0].ToString();

this.textBox7.Text = dsSeafood.Tables[0].Rows[i].ItemArray[1].ToString();

this.textBox8.Text = dsSeafood.Tables[0].Rows[i].ItemArray[2].ToString();

this.textBox9.Text = dsSeafood.Tables[0].Rows[i].ItemArray[3].ToString();

this.textBox10.Text = dsSeafood.Tables[0].Rows[i].ItemArray[4].ToString();
}
}



le workspace me renvoi l'erreur suivante :
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll
Additional information: Cannot find table 0.

si je comprend bien il ne trouve pas la table !!!
quelqu'un peut t'il m'éclairer

CDLT
PHILO

1 réponse

cs_coq Messages postés 6350 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
5 août 2005 à 19:03
Salut,

Si il ne trouve pas la table d'index 0 c'est que tu n'as pas récupérer de données en executant ta requete.

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
Rejoignez-nous