0

I have the following code

using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Login.DB_Path + ";Jet OLEDB:Database Password=*************"))
        {
            conn.Open();
            OleDbCommand cmd = new OleDbCommand
            {
                Connection = conn,
                CommandText = string.Format("SELECT {1} FROM {0} WHERE {2} = ? AND {3} = ? AND {4} = ? AND {5} = ?",
                Constants.tbnm_stock_collapsed,
                Constants.clnm_Stock,
                Constants.clnm_modelo,
                Constants.clnm_colores,
                Constants.clnm_tallas,
                Constants.clnm_tenda)
            };
            cmd.Parameters.AddWithValue("?", int.Parse(model));
            cmd.Parameters.AddWithValue("?", int.Parse(color));
            cmd.Parameters.AddWithValue("?", int.Parse(talla));
            cmd.Parameters.AddWithValue("?", Sendfrom_CB.SelectedIndex);
            var var_stock = cmd.ExecuteScalar();
            int stock;
            int.TryParse(Send_Count_TB.Text,out stock);
            stock = int.Parse(var_stock.ToString()) - stock;
            cmd = new OleDbCommand
            {
                Connection = conn,
                CommandText = string.Format("UPDATE {0} SET {1} = ? WHERE {2} = ? AND {3} = ? AND {4} = ? AND {5} = ?",
                Constants.tbnm_stock_collapsed,
                Constants.clnm_Stock,
                Constants.clnm_modelo,
                Constants.clnm_colores,
                Constants.clnm_tallas,
                Constants.clnm_tenda)
            };
            cmd.Parameters.AddWithValue("?", stock);
            cmd.Parameters.AddWithValue("?", int.Parse(model));
            cmd.Parameters.AddWithValue("?", int.Parse(color));
            cmd.Parameters.AddWithValue("?", int.Parse(talla));
            cmd.Parameters.AddWithValue("?", Sendfrom_CB.SelectedIndex);
            int effect = cmd.ExecuteNonQuery();

I've read all the documentation. So i am using ? in the query and addwithvalue as a method on to pass the parameter. i've checked the query and there is no error (atleast i don't see it). The worst part of all is that in the result of the execution the parameter effect have a value of 1, as i understand this would mean that there is a row affected, but when i reload the datatable there is no change in the DB.

EDIT: i've added a bit of code. The using part is the same for both, the select one is working and give the correct stock, the update no.

EDIT 2: Path directing to the DB

public static string DB_Path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\folder" + "\\DB.accdb";
  • https://stackoverflow.com/q/17147249/1070452 – Ňɏssa Pøngjǣrdenlarp May 03 '19 at 00:04
  • You might be connected to a different database than you think or maybe the query you are using to check the database is not quite right. Put a break point in there and look at the Connection to see where it is really connected. – Crowcoder May 03 '19 at 00:04
  • @NatPongjardenlarp i read the post you linked by i don't quite understand what it's the problem, i've edited the code a bit, the problem is in the definition of the path? –  May 03 '19 at 00:14
  • So as i understand there is a delay, visual studio creates a temporal dB in debug folder than then it is copied to the original. Anyway to bipass this copy? –  May 03 '19 at 00:42

0 Answers0