La requette d'insertion

Résolu
Marakima Messages postés 36 Date d'inscription jeudi 2 octobre 2008 Statut Membre Dernière intervention 26 septembre 2009 - 6 mai 2008 à 01:16
didel84 Messages postés 2 Date d'inscription mardi 6 mai 2008 Statut Membre Dernière intervention 6 mai 2008 - 6 mai 2008 à 19:55
Bonsoir tous le monde ,
 Je suis débutante en C#,
alors je réalise une application en C# et MySql,
j'ai effectuer la requette de selection dont voiçi le code : (j'ai utiliser using MySql.Data.MySqlClient)
--------------------------------------------------------------- 
private void button1_Click(object sender, System.EventArgs e)  
{   
string MyConString = "SERVER=localhost;" + "DATABASE=mydatabase;" + "UID=testuser;" +"PASSWORD=testpassword;";  
 MySqlConnection connection = new MySqlConnection(MyConString);  
 MySqlCommand command = connection.CreateCommand();  
 MySqlDataReader Reader;   

command.CommandText = "select * from mycustomers";   
connection.Open();   

Reader = command.ExecuteReader();  
 while (Reader.Read())   
{    
string thisrow = "";    
for (int i= 0;i<Reader.FieldCount;i++)      thisrow+=Reader.GetValue(i).ToString() + ",";    
listBox1.Items.Add(thisrow);   
}   
connection.Close();  
}
---------------------------------------------------------------------------

et je voudrais faire la même chose pour l'insertion, alors some help pleaze!!

1 réponse

didel84 Messages postés 2 Date d'inscription mardi 6 mai 2008 Statut Membre Dernière intervention 6 mai 2008
6 mai 2008 à 19:55
Un exemple :

string MySQLCmd = "INSERT INTO table1(champ1) value ('essai')";
try
{
MySqlConnection mySqlConnection = new MySqlConnection("Database=xxx;Data Source=xx.xx.xx.xx;User Id=xxx;Password=xxx");
    MySqlCommand mySqlCommand = new MySqlCommand(MySQLCmd, mySqlConnection);
    mySqlCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
3
Rejoignez-nous