Why I can't update data in my database MSAccess?
though, it's already working, but no changes.

Pls help me...

Here's my code for Update
I have 10 Fields in my table Personaldata

try
            {
                Records f1 = new Records();
                BlockNo = textBox1.ToString();
                LotNo = textBox2.ToString();
                Numberofoccupants = textBox3.ToString();
                Firstname = textBox4.ToString();
                Familyname = textBox5.ToString();
                Dateofbirth = textBox6.ToString();
                Age = textBox7.ToString();
                Bloodtype = textBox8.ToString();
                Placeofbirth = textBox9.ToString();
                Religion = textBox10.ToString();


                string SQLUpdateString;

                if (BlockNo == "")
                {
                    SQLUpdateString = "UPDATE Personaldata SET BlockNo ='" + BlockNo+ "', LotNo='" + LotNo + "', Numberofoccupants='" + Numberofoccupants + "', Firstname='" + Firstname + "', Familyname='" + Familyname + "', Dateofbirth='" + Dateofbirth + "', Age='" + Age + "', Placeofbirth='" + Placeofbirth + "', Religion='" + Religion + "' WHERE BlockNo='" + BlockNo + "'";
                }
                else
                {
                    SQLUpdateString = "UPDATE Personaldata SET BlockNo ='" + BlockNo + "', LotNo='" + LotNo + "', Numberofoccupants='" + Numberofoccupants + "', Firstname='" + Firstname + "', Familyname='" + Familyname + "', Dateofbirth='" + Dateofbirth + "', Age='" + Age + "', Placeofbirth='" + Placeofbirth + "', Religion='" + Religion + "' WHERE BlockNo='" + BlockNo + "'";
                }




                OleDbCommand SQLCommand = new OleDbCommand();
                SQLCommand.CommandText = SQLUpdateString;
                SQLCommand.Connection = f1.database;
                int response = SQLCommand.ExecuteNonQuery();
                MessageBox.Show("Update successful!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();
                Records frm = new Records();
                frm.Show();
            }

            catch (Exception)
            {
                MessageBox.Show("something wrong");
            }

Thank you

Recommended Answers

All 3 Replies

Is this code causing an exception? What's the error?

sir JorgeM, there's no error, in fact It's working, when I click the button update its shows "update successful!".However, there's no changes in the database.

Can you be sure a record will be found to update, given the test
WHERE BlockNo='" + BlockNo + "'"
and the fact that BlockNo is allowed to be an empty string?

Why the test
if (BlockNo == "")
if the code in both blocks is practically identical?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.