I have a class Variables where I declare my tables. eg:
public static DataSet dsFoods = new DataSet();
I have a class Common where I have my data access routines.
At startup I use this to fill the datasets:
Works fine. And I can add a row to the table.
But if I want to edit the table, I have problems saving the changes.
I end up with a dataset called changes which has the changes to dsFoods in it.
In Common, I have this:
I call it, never minding the rest,:
resultStr = Common.SaveDatasetChanges(inds, ""Foods");
where inds is the dataset containing the changes.
I get an error:
Update unable to find TableMapping['Foods'] or DataTable 'Foods'
I have spent hours fiddling but I am getting nowhere.
public static DataSet dsFoods = new DataSet();
I have a class Common where I have my data access routines.
At startup I use this to fill the datasets:
C#:
sql = [COLOR=#0000ff]"SELECT * FROM "[/COLOR] + datasetName;
SQLiteCommand selectSQL = [COLOR=#008b8b][B]new[/B][/COLOR] [COLOR=#191970][B]SQLiteCommand[/B][/COLOR](sql);
selectSQL.Connection = Variables.conn;
SQLiteDataAdapter da = [COLOR=#008b8b][B]new[/B][/COLOR] [COLOR=#191970][B]SQLiteDataAdapter[/B][/COLOR](selectSQL);
[COLOR=#008080][B]try[/B][/COLOR]
{
da.[COLOR=#191970][B]Fill[/B][/COLOR](whichDataset);
}
[COLOR=#008080][B]catch[/B][/COLOR] (Exception ex)
{
errorString = [COLOR=#0000ff]"Error filling dataset "[/COLOR] + datasetName + [COLOR=#0000ff]"."[/COLOR] + Environment.NewLine +
[COLOR=#0000ff]"Returned error is:"[/COLOR] + Environment.NewLine +
ex.Message;
MessageBox.[COLOR=#191970][B]Show[/B][/COLOR](errorString);
[COLOR=#000080]return[/COLOR] [COLOR=#008b8b][B]false[/B][/COLOR];
}
[COLOR=#008080][B]finally[/B][/COLOR]
{
Variables.conn.[COLOR=#191970][B]Close[/B][/COLOR]();
}
[COLOR=#000080]return[/COLOR] [COLOR=#008b8b][B]true[/B][/COLOR];
Works fine. And I can add a row to the table.
But if I want to edit the table, I have problems saving the changes.
I end up with a dataset called changes which has the changes to dsFoods in it.
In Common, I have this:
C#:
[COLOR=#0000ff][B]public[/B][/COLOR] [COLOR=#a52a2a]static[/COLOR] [COLOR=#ff0000]string[/COLOR] [COLOR=#191970][B]SaveDatasetChanges[/B][/COLOR](DataSet inds, [COLOR=#ff0000]string[/COLOR] tableName)
{
SQLiteCommand cmd = [COLOR=#008b8b][B]new[/B][/COLOR] [COLOR=#191970][B]SQLiteCommand[/B][/COLOR]([COLOR=#0000ff]""[/COLOR], Variables.conn);
SQLiteDataAdapter da = [COLOR=#008b8b][B]new[/B][/COLOR] [COLOR=#191970][B]SQLiteDataAdapter[/B][/COLOR](cmd);
SQLiteCommandBuilder cb = [COLOR=#008b8b][B]new[/B][/COLOR] [COLOR=#191970][B]SQLiteCommandBuilder[/B][/COLOR](da);
[COLOR=#ff0000][B]int[/B][/COLOR] numRows = [COLOR=#00008b]0[/COLOR];
[COLOR=#008080][B]try[/B][/COLOR]
{
Variables.conn.[COLOR=#191970][B]Open[/B][/COLOR]();
numRows = da.[COLOR=#191970][B]Update[/B][/COLOR](inds, tableName);
}
[COLOR=#008080][B]catch[/B][/COLOR] (Exception ex)
{
[COLOR=#000080]return[/COLOR] ex.Message;
}
[COLOR=#000080]return[/COLOR] numRows.[COLOR=#191970][B]ToString[/B][/COLOR]();
}
I call it, never minding the rest,:
resultStr = Common.SaveDatasetChanges(inds, ""Foods");
where inds is the dataset containing the changes.
I get an error:
Update unable to find TableMapping['Foods'] or DataTable 'Foods'
I have spent hours fiddling but I am getting nowhere.