0

Given that query is a valid update statement, the following code executes to completion, no errors. But no changes are made to the db. It fails silently.

            cmdSQL.CommandText = query;
            Con.Open();
            cmdSQL.Transaction = Con.BeginTransaction();
            cmdSQL.ExecuteNonQuery();    //returns 1 where expected
            cmdSQL.Transaction.Commit();
            Con.Close();

so does this:

            cmdSQL.CommandText = query;
            Con.Open();
            cmdSQL.Transaction = Con.BeginTransaction();

            SqlDataReader reader;
            reader = cmdSQL.ExecuteReader();

            int fields = reader.FieldCount;
            while (reader.Read())
            {
                for (int i = 0; i < fields; i++)
                    details.Add("" + reader[i]);
            }

            reader.Close();
            cmdSQL.Transaction.Commit();
            Con.Close();

Here's the connection string:

Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\LocalDB.mdf;Integrated Security=True

So the question is: How do I get updates to work?

PS: select statements work fine.

PPS. The database was created through visual studio 2013... It's a service based database

PPPS. I asked this question too... I assume they have a similar answers. Same problem, different approach: TableAdapter.Update returns 1 but no changes in db

13
  • 1
    What do you mean with code fails silently? Did you follow the code with a debugger and did you see the code executed without any error message? Neither an exception raised and catched by a try/block? Commented Jun 25, 2014 at 12:41
  • You should generally check the return code to see if an error occurred. You may lack update permission in SQL Server for example. Commented Jun 25, 2014 at 12:41
  • 1
    @JonnyBoats--the ExecuteNonQuery return code is the number of rows updated (so check if > 0), whereas insufficient permissions will result in an exception being thrown. Commented Jun 25, 2014 at 12:44
  • Are there any triggers on the database preventing updates? Commented Jun 25, 2014 at 13:16
  • @Steve: I mean there were no errors. Everything executed. No data was changed in the database. Commented Jun 25, 2014 at 13:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.