Ajout d'une ligne dans un datagrid.

Thanos_the_yopper Messages postés 309 Date d'inscription vendredi 9 janvier 2004 Statut Membre Dernière intervention 5 mars 2009 - 23 mars 2005 à 16:04
Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 - 24 mars 2005 à 11:26
J'ai un datagrid que je remplie via un dataset lui même remplit via une table d'une base de donnée SQL Server.
j'arrive parfaitement à remplir la datagrid, à faire un update sur une colonne qui existe déjà, mais j'ai un comportement étrange sur l'ajout d'une ligne. Je remplie tout mes champs (dont le premier qui est la clé primaire et qui ne peut être null) et quand je change de ligne, à la place de ce que j'ai mis dans la première colonne, ça me met null en me disant que cette colonne ne peut-être null >_< (voir http://ff.gamesmemories.com/images/temp/prob_datagrid.jpg. Je précise bien que à la base, le champs IdBob est bien rempli)
est-ce que quelqu'un à une idée de ce qu'il se passe ?

Merci d'avance ^__^

Final Fantasy Memories
Zelda Memories
Games Memories

7 réponses

Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 14
24 mars 2005 à 10:42
on peu voir un bout de code ???


Arthenius
http://blogs.developpeur.org/Arthenius/

"Ce qui ne me tue pas, me rend plus fort..."
0
Thanos_the_yopper Messages postés 309 Date d'inscription vendredi 9 janvier 2004 Statut Membre Dernière intervention 5 mars 2009
24 mars 2005 à 10:53
oh ben oui, je peux meme mettre tout le code ;) c'est quasi que du code généré par Visual Studio.


#region Code généré par le Concepteur Windows Form



/// <summary>



/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas



/// le contenu de cette méthode avec l'éditeur de code.



/// </summary>



private
void InitializeComponent()


{



this.button1 =
new System.Windows.Forms.Button();



this.sqlConnection1 =
new System.Data.SqlClient.SqlConnection();



this.sqlDataAdapter1 =
new System.Data.SqlClient.SqlDataAdapter();



this.sqlDeleteCommand1 =
new System.Data.SqlClient.SqlCommand();



this.sqlInsertCommand1 =
new System.Data.SqlClient.SqlCommand();



this.sqlSelectCommand1 =
new System.Data.SqlClient.SqlCommand();



this.sqlUpdateCommand1 =
new System.Data.SqlClient.SqlCommand();



this.dataSet11 =
new EssaisADO.DataSet1();



this.dataGrid1 =
new System.Windows.Forms.DataGrid();



this.button2 =
new System.Windows.Forms.Button();



this.button3 =
new System.Windows.Forms.Button();


((System.ComponentModel.ISupportInitialize)(
this.dataSet11)).BeginInit();


((System.ComponentModel.ISupportInitialize)(
this.dataGrid1)).BeginInit();



this.SuspendLayout();



//



// button1



//



this.button1.Location =
new System.Drawing.Point(16, 304);



this.button1.Name = "button1";



this.button1.TabIndex = 0;



this.button1.Text = "Fill";



this.button1.Click +=
new System.EventHandler(
this.button1_Click);



//



// sqlConnection1



//



this.sqlConnection1.ConnectionString = "workstation id="CALIZZANO-P";packet size=4096;user id=testADO;data source="SELL-M" +


"ISSION";persist security info=False;initial catalog=test;password=testADO";



//



// sqlDataAdapter1



//



this.sqlDataAdapter1.DeleteCommand =
this.sqlDeleteCommand1;



this.sqlDataAdapter1.InsertCommand =
this.sqlInsertCommand1;



this.sqlDataAdapter1.SelectCommand =
this.sqlSelectCommand1;



this.sqlDataAdapter1.TableMappings.AddRange(
new System.Data.Common.DataTableMapping[] {



new System.Data.Common.DataTableMapping("Table", "Essai1",
new System.Data.Common.DataColumnMapping[] {



new System.Data.Common.DataColumnMapping("IdBob", "IdBob"),



new System.Data.Common.DataColumnMapping("Qte1", "Qte1"),



new System.Data.Common.DataColumnMapping("Un1", "Un1"),



new System.Data.Common.DataColumnMapping("Qte2", "Qte2"),



new System.Data.Common.DataColumnMapping("Un2", "Un2")})});



this.sqlDataAdapter1.UpdateCommand =
this.sqlUpdateCommand1;



//



// sqlDeleteCommand1



//


this.sqlDeleteCommand1.CommandText @"DELETE FROM dbo.Essai1 WHERE (IdBob @Original_IdBob) AND (Qte1 = @Original_Qte1 OR @Original_Qte1 IS NULL AND Qte1 IS NULL) AND (Qte2 = @Original_Qte2 OR @Original_Qte2 IS NULL AND Qte2 IS NULL) AND (Un1 = @Original_Un1 OR @Original_Un1 IS NULL AND Un1 IS NULL) AND (Un2 = @Original_Un2 OR @Original_Un2 IS NULL AND Un2 IS NULL)";



this.sqlDeleteCommand1.Connection =
this.sqlConnection1;



this.sqlDeleteCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_IdBob", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "IdBob", System.Data.DataRowVersion.Original,
null));



this.sqlDeleteCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_Qte1", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Qte1", System.Data.DataRowVersion.Original,
null));



this.sqlDeleteCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_Qte2", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Qte2", System.Data.DataRowVersion.Original,
null));



this.sqlDeleteCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_Un1", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Un1", System.Data.DataRowVersion.Original,
null));



this.sqlDeleteCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_Un2", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Un2", System.Data.DataRowVersion.Original,
null));



//



// sqlInsertCommand1



//



this.sqlInsertCommand1.CommandText = "INSERT INTO dbo.Essai1(IdBob, Qte1, Un1, Qte2, Un2) VALUES (@IdBob, @Qte1, @Un1, " +


"@Qte2, @Un2); SELECT IdBob, Qte1, Un1, Qte2, Un2 FROM dbo.Essai1 WHERE (IdBob = " +


"@IdBob)";



this.sqlInsertCommand1.Connection =
this.sqlConnection1;



this.sqlInsertCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@IdBob", System.Data.SqlDbType.Int, 4, "IdBob"));



this.sqlInsertCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Qte1", System.Data.SqlDbType.Int, 4, "Qte1"));



this.sqlInsertCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Un1", System.Data.SqlDbType.VarChar, 5, "Un1"));



this.sqlInsertCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Qte2", System.Data.SqlDbType.Int, 4, "Qte2"));



this.sqlInsertCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Un2", System.Data.SqlDbType.VarChar, 5, "Un2"));



//



// sqlSelectCommand1



//



this.sqlSelectCommand1.CommandText = "SELECT IdBob, Qte1, Un1, Qte2, Un2 FROM dbo.Essai1";



this.sqlSelectCommand1.Connection =
this.sqlConnection1;



//



// sqlUpdateCommand1



//


this.sqlUpdateCommand1.CommandText @"UPDATE dbo.Essai1 SET IdBob @IdBob, Qte1 = @Qte1, Un1 = @Un1, Qte2 = @Qte2, Un2 = @Un2 WHERE (IdBob = @Original_IdBob) AND (Qte1 = @Original_Qte1 OR @Original_Qte1 IS NULL AND Qte1 IS NULL) AND (Qte2 = @Original_Qte2 OR @Original_Qte2 IS NULL AND Qte2 IS NULL) AND (Un1 = @Original_Un1 OR @Original_Un1 IS NULL AND Un1 IS NULL) AND (Un2 = @Original_Un2 OR @Original_Un2 IS NULL AND Un2 IS NULL); SELECT IdBob, Qte1, Un1, Qte2, Un2 FROM dbo.Essai1 WHERE (IdBob = @IdBob)";



this.sqlUpdateCommand1.Connection =
this.sqlConnection1;



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@IdBob", System.Data.SqlDbType.Int, 4, "IdBob"));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Qte1", System.Data.SqlDbType.Int, 4, "Qte1"));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Un1", System.Data.SqlDbType.VarChar, 5, "Un1"));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Qte2", System.Data.SqlDbType.Int, 4, "Qte2"));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Un2", System.Data.SqlDbType.VarChar, 5, "Un2"));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_IdBob", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "IdBob", System.Data.DataRowVersion.Original,
null));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_Qte1", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Qte1", System.Data.DataRowVersion.Original,
null));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_Qte2", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Qte2", System.Data.DataRowVersion.Original,
null));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_Un1", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Un1", System.Data.DataRowVersion.Original,
null));



this.sqlUpdateCommand1.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Original_Un2", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Un2", System.Data.DataRowVersion.Original,
null));



//



// dataSet11



//



this.dataSet11.DataSetName = "DataSet1";



this.dataSet11.Locale =
new System.Globalization.CultureInfo("fr-FR");



//



// dataGrid1



//



this.dataGrid1.CaptionText = "Essai ADO";



this.dataGrid1.DataBindings.Add(
new System.Windows.Forms.Binding("Tag",
this.dataSet11, "Essai1.IdBob"));



this.dataGrid1.DataMember = "Essai1";



this.dataGrid1.DataSource =
this.dataSet11;



this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;



this.dataGrid1.Location =
new System.Drawing.Point(104, 16);



this.dataGrid1.Name = "dataGrid1";



this.dataGrid1.Size =
new System.Drawing.Size(496, 232);



this.dataGrid1.TabIndex = 1;



//



// button2



//



this.button2.Location =
new System.Drawing.Point(104, 304);



this.button2.Name = "button2";



this.button2.TabIndex = 2;



this.button2.Text = "Update";



this.button2.Click +=
new System.EventHandler(
this.button2_Click);



//



// button3



//



this.button3.Location =
new System.Drawing.Point(208, 304);



this.button3.Name = "button3";



this.button3.Size =
new System.Drawing.Size(104, 23);



this.button3.TabIndex = 3;



this.button3.Text = "button3";



this.button3.Click +=
new System.EventHandler(
this.button3_Click);



//



// Form1



//



this.AutoScaleBaseSize =
new System.Drawing.Size(5, 13);



this.ClientSize =
new System.Drawing.Size(624, 334);



this.Controls.Add(
this.button3);



this.Controls.Add(
this.button2);



this.Controls.Add(
this.dataGrid1);



this.Controls.Add(
this.button1);



this.Name = "Form1";



this.Text = "Form1";


((System.ComponentModel.ISupportInitialize)(
this.dataSet11)).EndInit();


((System.ComponentModel.ISupportInitialize)(
this.dataGrid1)).EndInit();



this.ResumeLayout(
false);


}


#endregion



/// <summary>



/// Point d'entrée principal de l'application.



/// </summary>


[STAThread]



static
void Main()


{


Application.Run(
new Form1());


}



private
void button1_Click(
object sender, System.EventArgs e)


{



try


{



this.sqlDataAdapter1.Fill(
this.dataSet11, "Essai1") ;


}



catch( Exception ex)


{


String err = ex.Message ;


}


}



private
void button2_Click(
object sender, System.EventArgs e)


{



try


{



this.sqlDataAdapter1.Update(
this.dataSet11, "Essai1") ;


}



catch( Exception ex)


{


String err = ex.Message ;


}




}

Final Fantasy Memories
Zelda Memories
Games Memories
0
Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 14
24 mars 2005 à 11:07
ton champ ID c pas un identify par hasard ??


Arthenius
http://blogs.developpeur.org/Arthenius/

"Ce qui ne me tue pas, me rend plus fort..."
0
Thanos_the_yopper Messages postés 309 Date d'inscription vendredi 9 janvier 2004 Statut Membre Dernière intervention 5 mars 2009
24 mars 2005 à 11:11
heuu ou est-ce que je peux voir ça ?

Final Fantasy Memories
Zelda Memories
Games Memories
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 14
24 mars 2005 à 11:15
dans ta bdd ??
le champs est en autoincrement ...

sinon moi j'ai pas l'habitude d'utiliser la ligne append (celle avec le * en debut de ligne..)

pour les insert je fais un bouton qui fait un
DataRow row = ds.Tables["MaTable"].NewRow();
//Par exemple
row["ID"] = 500;

ds.Tables["MaTable"].Rows.Add(row);


Arthenius
http://blogs.developpeur.org/Arthenius/

"Ce qui ne me tue pas, me rend plus fort..."
0
Thanos_the_yopper Messages postés 309 Date d'inscription vendredi 9 janvier 2004 Statut Membre Dernière intervention 5 mars 2009
24 mars 2005 à 11:23
mais s'il est en autoincrement, comment on peut faire ? on peut ne pas le faire s'afficher dans la datagrid ce champs ?

Final Fantasy Memories
Zelda Memories
Games Memories
0
Arthenius Messages postés 1182 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 6 septembre 2011 14
24 mars 2005 à 11:26
en fait si c un autoincrement en theorie tu na rien a faire il va le recharger mais vu ton code j epense pas que ce soit un autoincrement


Arthenius
http://blogs.developpeur.org/Arthenius/

"Ce qui ne me tue pas, me rend plus fort..."
0
Rejoignez-nous