MySql connection in C# -


i making simple windows application form, register people in database, made connection class there it:

public void query_send(string cmd)     {           string config = "server=127.0.0.1;uid=root;database=bdcliente;";          mysqlconnection conn = new mysqlconnection(config);         mysqlcommand comm = new mysqlcommand(cmd, conn);         try         {             conn = new mysql.data.mysqlclient.mysqlconnection();             conn.connectionstring = config;             conn.open();         }         catch         {             messagebox.show("error when connecting database!");         }                 {             conn.close();         }     } 

and in button give informations mysql use this:

        private void button1_click(object sender, eventargs e)     {         query instance = new query();         instance.query_send("insert `tbcliente`(`codcliente`, `name`, `cpf`, `telephone`) values ([" + textbox1 + "],[" + textbox2 + "],[" + textbox3 + "],[" + textbox4 + "])");     } 

i error connection when click register button, may me or give me link of tutorial teaches correct way of doing this? thanks, iago.

my guess need wrap values clause results in single quotes sql generating invalid.

values ('" + textbox1 + "') 

brackets required when referring table or column names. not when you're referring string literals.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -