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";