Ajouter un enregistrement dans une base de données Mysql

Résolu
kabi14 Messages postés 50 Date d'inscription vendredi 8 avril 2011 Statut Membre Dernière intervention 28 juin 2011 - 27 juin 2011 à 12:35
kabi14 Messages postés 50 Date d'inscription vendredi 8 avril 2011 Statut Membre Dernière intervention 28 juin 2011 - 27 juin 2011 à 13:23
salut,

Je réalise une application (site web) sous visual studio 2010 avec une db mysql.
J'ai donc installé le connector 5.2 de mysql
Mais lors de insertion apartir d un formulaire ca marche pas
le code
MySqlDataAdapter apdat;
string p = TextBox10.Text;
string a= TextBox9.Text;
string c = TextBox8.Text;
DropDownList1.Items.Add(p);
string MyConString = "SERVER=localhost;" +
"DATABASE=t;" +
"UID=root;" +
"PASSWORD=;";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
connection.Open();
command.CommandText = "insert into h values (\'" + p + "\',\'" + a + "\',\'" + c + "\') ";

apdat = command.ExecuteNonQuery();


je croie que l' erreur c est dans ExecuteQuery qui n execute pas l insertion dans la base de donner
merci

1 réponse

kabi14 Messages postés 50 Date d'inscription vendredi 8 avril 2011 Statut Membre Dernière intervention 28 juin 2011
27 juin 2011 à 13:23
merci
j ai trouver la solution
string MyConString = "SERVER=localhost;" +"DATABASE=t;" +"UID=root;" +"PASSWORD=;";
MySqlConnection myConnection = new MySqlConnection(MyConString);
command.CommandText = "insert into h values (\'" + p + "\',\'" + a + "\',\'" + c + "\') ";
MySqlCommand myCommand = new MySqlCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
3
Rejoignez-nous