Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button1_Click(object sender, EventArgs e)
        {
            /*VirtualPet.Popup popup = new VirtualPet.Popup();
            popup.UpdatePopup();*/
            SqlCeConnection conn = new SqlCeConnection("Data Source=E:\\Project Final_Year\\Project Final\\MyProject\\ERU Implementation\\VirtualPetedit\\VirtualPet\\MyDB.sdf");
            string query = "UPDATE Events SET (event_name='" + this.textBox2.Text + "', event_description='" + this.richTextBox1.Text + "', event_type='" + this.comboBox1.SelectedItem + "', date='" + this.dateTimePicker1.Value + "', time='" + this.textBox3.Text +"')  WHERE event_id = " + textBox1.Text + ";";
            SqlCeCommand cmd = new SqlCeCommand(query, conn);
            try
            {
                conn.Open();
                SqlCeCommand command = new SqlCeCommand(query, conn);
                command.ExecuteNonQuery();
                VirtualPet.Popup popup = new VirtualPet.Popup();
                popup.UpdatePopup();
                conn.Close();
                //command.Parameters.AddWithValue("@EI", textBox4.Text);  
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
Posted
Updated 23-Apr-15 17:39pm
v2
Comments
DamithSL 23-Apr-15 23:43pm    
any exceptions?
PIEBALDconsult 24-Apr-15 0:21am    
Please don't form SQL statements by using concatenation! Please use a parameterized statement.
Also, create a Data Access Layer (class) rather than putting Data Access code directly in your UI code.

You don't say which database system, but (unlike an INSERT statement) an UPDATE statement doesn't use parentheses around the columns and values.
 
Share this answer
 
Update statement doesn't need a parenthesis. Why not try creating a stored procedure in the database so that you cant test it first there then call the procedure in the front end?

Update [table_name] set [Field_name] = [Object] where [Field_name] = [value]

also just a heads up, try to use parameters to avoid sql injection.
 
Share this answer
 

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