c# Insert lines into a database issue

elfenliedtopfan5 121 Reputation points
2021-03-02T01:33:09.813+00:00

Hello all that read,

i have written a little code to insert lines into a database i get a success message but nothing is appearing in the database it still blank,

code below,

                    try
                    {
                        Nao_Res.conn = new MySqlConnection();

                        Nao_Res.conn.ConnectionString = Nao_Res.connString;
                        Nao_Res.conn.Open();
                        MySqlCommand cmd = new MySqlCommand("INSERT INTO `Applications_Setup`(`Application`, `Installed`, `Description`) VALUES ('"+Nao_Res.Name+"','"+Nao_Res.AppName+"','"+"Photoshop this is a test for database"+"')");
                        XtraMessageBox.Show("Added");
                        Nao_Res.conn.Close();



                    }
                    catch (MySql.Data.MySqlClient.MySqlException ex)
                    {
                        XtraMessageBox.Show(ex.Message);
                    }

but unsure of why this is not working i have auto-increment on my id so removed it from the insert but quite sure its not that as should not make a difference if it auto increments,

below is a picture of the db setup on sqlserver,

30dgjlo.png

thanks in advance elfenliedtopfan5

SQL Server | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. cheong00 3,486 Reputation points Volunteer Moderator
    2021-03-02T01:40:14.197+00:00

    You have to call cmd.ExecuteNonQuery() to run the query...


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.