Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't insert or update data in mysql website.
Can someone please help?
Thanks.

What I have tried:

Insert COde:
<pre>String connString = System.Configuration.ConfigurationManager.ConnectionStrings["web"].ToString();
            List<JsonData> list = new List<JsonData>();
            using (conn = new MySqlConnection(connString))
            {
                using (MySqlCommand cmd = new MySqlCommand("INSERT INTO avance_actividad (idProyecto,idObjetivo,idResultado,actividad,estado,comentario,porcentaje)" + "VALUES('" + get(proy_id_click) + "','" + get(obj_click) + "','" + get(res_click) + "','" + get(act2_click) + "','" + get(es_click) + "','" + get(com_click) + "','" + get(por_click) + "')"))
                {
                    //conn.Open();
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = conn;
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }


Update Code:
String connString = System.Configuration.ConfigurationManager.ConnectionStrings["web"].ToString();
            conn = new MySql.Data.MySqlClient.MySqlConnection(connString);
            conn.Open();
            queryStr = "";
            //update avance_actividad set estado = 'nada', porcentaje = '0', comentario = 'nada' WHERE idProyecto = '1' and idObjetivo = '1' and idResultado = '1' and idActividad = '1'
            queryStr = "update avance_actividad set estado= '" + es_click + "', comentario= '" + com_click + "', porcentaje='" + por_click + "' where idProyecto='"+ proy_id_click+"' and idObjetivo='"+obj_click+"' and idResultado='"+res_click+"' and idActividad='"+act2_click+"'";
            cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn);
            cmd.ExecuteReader();
            conn.Close();
Posted
Comments
David_Wimbley 30-Jan-18 15:24pm    
Why can't you insert or update? What error are you getting? We don't have access to your code, your computer or your servers so how do you expect us to figure out the error on our own?

The other thing, your code is wide open for sql injection attacks.
Member 10850253 30-Jan-18 15:29pm    
Thanks for the replay.
I am not getting any errors.
I did some validation for the data that can be inserted on the fields, so the injection doesn't get me worried.
I don't know what is wrong.
Please help me.
Thanks.
an0ther1 30-Jan-18 18:46pm    
Use your debugger - I would suggest that your Insert & Update Statements are not properly formed & do not contain the values you expect.
For instance, what is the actual value of es_click, com_click etc? If these are objects then your statement will probably fail.
Use your debugger to view & get the value of cmd.Text, can you execute this in a MySQL Workbench?
Refer; MSDN: Debugging in Visual Studio

Kind Regards
Member 10850253 30-Jan-18 20:56pm    
I am using jQuery to set the onclick event, since the postback messes my website.
I am sending the text from my gui elements with jQuery.
Please let me know how I can solve my problem.
I will post my jquery code later.
Thanks.
an0ther1 30-Jan-18 21:55pm    
The code you have provided is C# - does this code get executed?
If the code is being executed then debug it.
If the code is not then you need to determine why, client side debugging can be done in various ways.

Kind Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900