'System.Data.SqlClient.SqlException' s'est produite dans system.data.dll ?????

lsprax83 Messages postés 17 Date d'inscription vendredi 2 septembre 2005 Statut Membre Dernière intervention 12 juillet 2008 - 24 nov. 2005 à 22:51
cs_torreshubert Messages postés 2 Date d'inscription vendredi 25 novembre 2005 Statut Membre Dernière intervention 28 octobre 2008 - 28 oct. 2008 à 14:51
bonjour tout le monde,
jai mis le code suivant :


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


{


SqlConnection cn=
new SqlConnection();


cn.ConnectionString=sqlConnection1.ConnectionString; //sqlConnection1 à été generé par l'assistant du sqlDataAdapter


SqlCommand insrt=
new SqlCommand("INSERT INTO(login,password) user VALUES('foad','453788')",cn);


sqlDataAdapter1.InsertCommand=insrt;


cn.Open();


sqlDataAdapter1.InsertCommand.ExecuteNonQuery(); // c au niveau de cette ligne que l'exception s'est levée


cn.Close();


}

pour inserer une nouvelle ligne dans la table "user" dans une base de donneé sql srver, mais il me donne l'exception suivante :" Une exception non gérée du type 'System.Data.SqlClient.SqlException' s'est produite dans system.data.dll


Informations supplémentaires : Erreur système.
"
NB:j'ai utiliser l'assistant de l'objet sqlDataAdapter qui m'a generer la connection,les commande sql et la dataset.

je me suis bloqué et je ne sais pas koi faire.
j'attens vos suggestions , aide koi ke se soit...
merci.

5 réponses

sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
25 nov. 2005 à 10:29
si je peux me permettre... quel est l'intérêt de recréer une connexion sachant qu'une autre existe déjà ?

Voici comment je recoderais :


private
void Form1_Load(
object sender, System.EventArgs e)
{
SqlCommand insrt=
new SqlCommand("INSERT INTO user (login,password) VALUES('foad','453788')", sqlConnection1);
cn.Open();
insrt.ExecuteNonQuery(); // c au niveau de cette ligne que l'exception s'est levée
cn.Close();

}

ta requête était fausse aussi.

Sébastien FERRAND
[MVP C#]
0
lsprax83 Messages postés 17 Date d'inscription vendredi 2 septembre 2005 Statut Membre Dernière intervention 12 juillet 2008
25 nov. 2005 à 15:09
il me donne la même exception, aprés la réctification !!!!
voici le message de l'exception :
" Une exception non gérée du type 'System.Data.SqlClient.SqlException' s'est produite dans system.data.dll

Informations supplémentaires : Erreur système."
toujour le compilateur arrete dans cette ligne : insrt.ExecuteNonQuery();
0
sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
25 nov. 2005 à 15:21
tu peux remettre tout bout de code corriger ?

Sébastien FERRAND
[MVP C#]
0
lsprax83 Messages postés 17 Date d'inscription vendredi 2 septembre 2005 Statut Membre Dernière intervention 12 juillet 2008
25 nov. 2005 à 20:10
voila tout le code :

using System;


using System.Drawing;


using System.Collections;


using System.ComponentModel;


using System.Windows.Forms;


using System.Data;


using System.Data.SqlClient;


namespace tp1


{


/// <summary>


/// Description résumée de Form1.


/// </summary>


public class
Form1 : System.Windows.Forms.Form


{


private
System.Windows.Forms.TextBox textBox1;


private
System.Windows.Forms.TextBox textBox2;


private
System.Windows.Forms.Button button1;


private
System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;


private
System.Data.SqlClient.SqlCommand sqlSelectCommand1;


private
System.Data.SqlClient.SqlCommand sqlInsertCommand1;


private
System.Data.SqlClient.SqlCommand sqlUpdateCommand1;


private
System.Data.SqlClient.SqlCommand sqlDeleteCommand1;


public
System.Data.SqlClient.SqlConnection sqlConnection1;


private
tp1.DataSet1 dataSet11;


private
System.Windows.Forms.DataGrid dataGrid1;


/// <summary>


/// Variable nécessaire au concepteur.


/// </summary>


private System.ComponentModel.Container components = null
;


public
Form1()


{


//


// Requis pour la prise en charge du Concepteur Windows Forms


//


InitializeComponent();


//


// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent


//


}


/// <summary>


/// Nettoyage des ressources utilisées.


/// </summary>


protected override void Dispose( bool
disposing )


{


if
( disposing )


{


if (components != null
)


{


components.Dispose();


}


}


base
.Dispose( disposing );


}


#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.textBox1 = new
System.Windows.Forms.TextBox();


this.textBox2 = new
System.Windows.Forms.TextBox();


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


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


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


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


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


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


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


this.dataSet11 = new
tp1.DataSet1();


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


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


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


this
.SuspendLayout();


//


// textBox1


//


this.textBox1.Location = new
System.Drawing.Point(104, 32);


this
.textBox1.Name = "textBox1";


this
.textBox1.TabIndex = 0;


this
.textBox1.Text = "";


//


// textBox2


//


this.textBox2.Location = new
System.Drawing.Point(104, 64);


this
.textBox2.Name = "textBox2";


this
.textBox2.TabIndex = 1;


this
.textBox2.Text = "";


//


// button1


//


this.button1.Location = new
System.Drawing.Point(168, 96);


this
.button1.Name = "button1";


this.button1.Size = new
System.Drawing.Size(32, 24);


this
.button1.TabIndex = 2;


this
.button1.Text = "ok";


//


// 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", "user", new
System.Data.Common.DataColumnMapping[] {


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


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


this.sqlDataAdapter1.UpdateCommand = this
.sqlUpdateCommand1;


//


// sqlDeleteCommand1


//


this.sqlDeleteCommand1.CommandText "DELETE FROM [user] WHERE (login @Original_login) AND (password = @Original_pass" +


"word OR @Original_password IS NULL AND password IS NULL)";


this.sqlDeleteCommand1.Connection = this
.sqlConnection1;


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


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


//


// sqlConnection1


//


this
.sqlConnection1.ConnectionString = "workstation id=LACHGAR;packet size=4096;integrated security=SSPI;data source=lach" +


"gar;persist security info=False;initial catalog=test";


//


// sqlInsertCommand1


//


this
.sqlInsertCommand1.CommandText = "INSERT INTO [user] (login, password) VALUES (@login, @password); SELECT login, pa" +


"ssword FROM [user] WHERE (login = @login)";


this.sqlInsertCommand1.Connection = this
.sqlConnection1;


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


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


//


// sqlSelectCommand1


//


this
.sqlSelectCommand1.CommandText = "SELECT login, password FROM [user]";


this.sqlSelectCommand1.Connection = this
.sqlConnection1;


//


// sqlUpdateCommand1


//


this.sqlUpdateCommand1.CommandText "UPDATE [user] SET login @login, password = @password WHERE (login = @Original_l" +


"ogin) AND (password = @Original_password OR @Original_password IS NULL AND passw" +


"ord IS NULL); SELECT login, password FROM [user] WHERE (login = @login)";


this.sqlUpdateCommand1.Connection = this
.sqlConnection1;


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


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


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


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


//


// dataSet11


//


this
.dataSet11.DataSetName = "DataSet1";


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


//


// dataGrid1


//


this
.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;


this
.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;


this
.dataGrid1.BackgroundColor = System.Drawing.Color.LightGray;


this
.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;


this
.dataGrid1.CaptionBackColor = System.Drawing.Color.LightSteelBlue;


this.dataGrid1.CaptionFont = new
System.Drawing.Font("Microsoft Sans Serif", 8F);


this
.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;


this
.dataGrid1.DataMember = "user";


this.dataGrid1.DataSource = this
.dataSet11;


this.dataGrid1.FlatMode = true
;


this.dataGrid1.Font = new
System.Drawing.Font("Microsoft Sans Serif", 8F);


this
.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;


this
.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;


this
.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;


this
.dataGrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue;


this.dataGrid1.HeaderFont = new
System.Drawing.Font("Microsoft Sans Serif", 8F);


this
.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;


this
.dataGrid1.LinkColor = System.Drawing.Color.Teal;


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


this
.dataGrid1.Name = "dataGrid1";


this
.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;


this
.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;


this
.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;


this
.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;


this.dataGrid1.Size = new
System.Drawing.Size(208, 96);


this
.dataGrid1.TabIndex = 3;


//


// Form1


//


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


this.ClientSize = new
System.Drawing.Size(384, 285);


this.Controls.Add(this
.dataGrid1);


this.Controls.Add(this
.button1);


this.Controls.Add(this
.textBox2);


this.Controls.Add(this
.textBox1);


this
.Name = "Form1";


this
.Text = "Form1";


this.Load += new System.EventHandler(this
.Form1_Load);


((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 Form1_Load(object
sender, System.EventArgs e)


{


sqlInsertCommand1=
new SqlCommand("INSERT INTO user(login,password) VALUES('foad','453788')",sqlConnection1);


sqlConnection1.Open();


sqlInsertCommand1.ExecuteNonQuery();


sqlConnection1.Close();


}


}


}
0

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

Posez votre question
cs_torreshubert Messages postés 2 Date d'inscription vendredi 25 novembre 2005 Statut Membre Dernière intervention 28 octobre 2008
28 oct. 2008 à 14:51
j'ai eu le meme probleme puis lorque j'ai changé le nom de la classe user en utilisateur et bien c'est passé essaie et tu verras
0
Rejoignez-nous