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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,327 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,630 questions
0 comments No comments
{count} votes

Accepted answer
  1. Cheong00 3,476 Reputation points
    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