Asp.net C# (GridView_RowUpdating)

Hajjoura1987 Messages postés 5 Date d'inscription vendredi 18 mars 2011 Statut Membre Dernière intervention 12 juin 2011 - 2 mai 2011 à 23:42
nhervagault Messages postés 6063 Date d'inscription dimanche 13 avril 2003 Statut Membre Dernière intervention 15 juillet 2011 - 4 mai 2011 à 21:39
[b]bjr,
Je suis entrain de programmer une application web sur VisualStudio2008 par C#
mais j'ai un problème dans la mise à jour de base de donnée par la méthode (GridView1_RowUpdating)
SVP, pouvez vous m'aidez par un un petit exemple
/b
Voilà mon code, mais il fonctionne pas:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                SqlConnection connection = new SqlConnection();
                connection.ConnectionString = "Data Source=...";
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {

                    string log = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;

                    string pwd = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;

                    string d = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;

                    string nom = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;

                    string pre = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;

                    string tel = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text;

                    string mail = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text;




                    SqlCommand sqlcommand6 new SqlCommand("UPDATE [pfe2011].[dbo].[Developpeur] SET [nomUti]log,[Password_d] =pwd,[Droit] = D,[Nom_d]= no,[Prénom_d] = pre,[Num_tel] = tel,[email] = mail'");
                    sqlcommand6.Connection = connection;
                   sqlcommand6.ExecuteScalar ();
                   // sqlcommand6.ExecuteNonQuery();
                 
                    
                    
                }
            }
            catch (Exception E)
            { }
        
        }

1 réponse

nhervagault Messages postés 6063 Date d'inscription dimanche 13 avril 2003 Statut Membre Dernière intervention 15 juillet 2011 37
4 mai 2011 à 21:39
Salut,

Ouille, il faut que tu revois les bases d'ADO.NET.
GridView1_RowUpdating est-il appellé?

Sinon ta requete est fausse.

command.Parameters.Add(
new SqlParameter(
“@log“, SqlDbType.NChar, 5)).Value = log;
.......

//voici la requete refaite
UPDATE [pfe2011].[dbo].[Developpeur] 
SET [nomUti] = @log,
[Password_d] =@pwd,
[Droit] = @D,
[Nom_d]= @no,
[Prénom_d] = @pre,
[Num_tel] = @tel,
[email] = @mail


il faut appeler executequery et non reader
0
Rejoignez-nous