Good evening,
I get an error on this line :
I want to be able to convert my character string to INT otherwise I could not insert the value into the database if it is not an integer.
Here is the code for my INSERT INTO query :
And this is the code of my fonction to get the list of categories in String :
I need your help PLS!
I get an error on this line :
C#:
command.Parameters.AddWithValue("@chambreCat", Convert.ToInt32(cbAdminCat.Text));
I want to be able to convert my character string to INT otherwise I could not insert the value into the database if it is not an integer.
Here is the code for my INSERT INTO query :
C#:
//Ajout des chambres (Admin) / A finir
private void btnEnregChambresAdmin_Click(object sender, EventArgs e)
{
string cs = @"server=localhost;userid=root;password=;database=gestionhotelentretien;charset=utf8";
MySqlConnection connection = new MySqlConnection(@cs);
string query = "INSERT INTO utilisateur (CHAMBREID,CHAMBRENOM,CHAMBRECATEGORIE) VALUES(@chambreID,@chambreNom,@chambreCat)";
MySqlCommand command = new MySqlCommand(query, connection);
command.Parameters.AddWithValue("@chambreID", txtChNumId.Text);
command.Parameters.AddWithValue("@chambreNom", txtNameChambres.Text);
//Finir l'ajout de la catégorie
command.Parameters.AddWithValue("@chambreCat", Convert.ToInt32(cbAdminCat.Text));
try
{
connection.Open();
command.ExecuteNonQuery();
//Console.WriteLine("L'insertion a bien été effectuée !");
string messageInsertAgent = "L'insertion a bien été effectuée ! ";
MessageBox.Show(messageInsertAgent);
}
catch (MySqlException error)
{
Console.WriteLine("Error Generated. Details: " + error.ToString());
string messageErrorInsertAgent = "La requête contient une ou plusieurs erreurs ! ";
MessageBox.Show(messageErrorInsertAgent);
}
finally
{
connection.Close();
}
}
And this is the code of my fonction to get the list of categories in String :
C#:
//Fonction récupérant la liste des noms des catégories
public static List<String> GetLesCategoriesPourAjout()
{
List<String> listeDesCategories = new List<String>();
string query = "SELECT DISTINCT CATID, CATNOM FROM categorie";
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = query;
using (MySqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
listeDesCategories.Add(rdr.GetString("CATNOM"));
}
}
return listeDesCategories;
}
I need your help PLS!