Hi,
I seem to have some problems updating my dataset, I always get a error that
no rows were updated...:
An unhandled exception of type 'System.Data.DBConcurrencyException' occurred
in system.data.dll
Additional information: Concurrency violation: the UpdateCommand affected 0
records.
If anyone would have a look at it , I would appreciate it.
Al works fine for the insert and the update works in another dataaccessor so
I shouldn't be my OleDbHelper.
Thanks.
public class ReagentDataAccessor : DataAccessor{
public ReagentDataAccessor() {
ReagentDataset ds = this.GetReagents();
ds.Reagents[0].Name = "Blabla";
this.Update(ds);
}
public ReagentDataset GetReagents() {
ReagentDataset ds = new ReagentDataset();
string sql = "Select * from Reagents";
OleDbHelper.FillDataset(this.Connection, CommandType.Text,
sql, ds, new string[]{ "Reagents" });
return ds;
}
public void Update(ReagentDataset ds){
OleDbHelper.UpdateDataset(this.GetInsertCommand(),
this.GetDeleteCommand(),
this.GetUpdateCommand(),
ds,
"Reagents");
}
protected override OleDbCommand GetInsertCommand(){
string sql = "Insert into Reagents (SkillId, Name, NPCPrice,
StackSize, PlacesFound, BImg) values (@SkillId, @Name, @NPCPrice,
@StackSize, @PlacesFound, @BImg)";
OleDbCommand cmd = new OleDbCommand(sql, this.Connection);
cmd.Parameters.Add("@SkillId", OleDbType.Integer, 0, "SkillId");
cmd.Parameters.Add("@Name", OleDbType.VarChar, 255, "Name");
cmd.Parameters.Add("@NPCPrice", OleDbType.Double, 0, "NPCPrice");
cmd.Parameters.Add("@StackSize", OleDbType.Integer, 0, "StackSize");
cmd.Parameters.Add("@PlacesFound", OleDbType.WChar, 0,
"PlacesFound");
cmd.Parameters.Add("@BImg", OleDbType.VarChar, 255, "BImg");
return cmd;
}
protected override OleDbCommand GetUpdateCommand(){
string sql = "UPDATE Reagents SET SkillId=@SkillId, Name=@Name WHERE
Id=@Id";
OleDbCommand cmd = new OleDbCommand(sql, this.Connection);
cmd.Parameters.Add("@Id", OleDbType.Integer, 0, "Id");
cmd.Parameters.Add("@SkillId", OleDbType.Integer, 0, "SkillId");
cmd.Parameters.Add("@Name", OleDbType.VarChar, 255, "Name");
// string sql = "Update Reagents set SkillId=@skillid, Name=@name,
NPCPrice=@npcprice, StackSize=@stacksize, PlacesFound=@placesfound,
BImg=@bimg Where Id=@id";
// OleDbCommand cmd = new OleDbCommand(sql, this.Connection);
// cmd.Parameters.Add("@id", OleDbType.Integer, 0, "Id");
// cmd.Parameters.Add("@skillid", OleDbType.VarChar, 255,
"SkillId");
// cmd.Parameters.Add("@name", OleDbType.VarChar, 255, "Name");
// cmd.Parameters.Add("@npcprice", OleDbType.Double, 0, "NPCPrice");
// cmd.Parameters.Add("@stacksize", OleDbType.Integer, 0,
"StackSize");
// cmd.Parameters.Add("@placesfound", OleDbType.WChar, 0,
"PlacesFound");
// cmd.Parameters.Add("@bimg", OleDbType.VarChar, 255, "BImg");
return cmd;
}
protected override OleDbCommand GetDeleteCommand(){
string sql = "Delete from Reagents where Id=@Id";
OleDbCommand cmd = new OleDbCommand(sql, this.Connection);
cmd.Parameters.Add("@Id", OleDbType.Integer, 0, "Id");
return cmd;
}
}