C
canoewhiteh2o
I am having trouble adding data columns to a disconnected database. I
first load a datatable using:
private DataTable dtMacros = new DataTable();
private ArrayList macro = new ArrayList();
private SQLiteConnection cn;
private SQLiteDataAdapter adapterMacros;
cn = new SQLiteConnection("Data Source = irDatabase.db3");
SQLiteCommand commandMacros = new SQLiteCommand();
commandMacros.CommandText = "SELECT * FROM irMacros";
adapterMacros = new SQLiteDataAdapter(commandMacros.CommandText,
cn);
SQLiteCommandBuilder builderMacros = new
SQLiteCommandBuilder(adapterMacros);
adapterMacros.Fill(dtMacros);
dtMacros.PrimaryKey = new DataColumn[]
{ dtMacros.Columns["MacroName"] };
I am using an arraylist (macro) to store values for a new row - all
values are strings.
Later I update the data with the following code:
private void UpdateMacroDatabase(ArrayList macro, string macroName)
{
//Add datatable columns if needed for the datatable in
memory
if (dtMacros.Columns.Count <= macro.Count)
{
int i = dtMacros.Columns.Count;
while (i <= macro.Count)
{
dtMacros.Columns.Add("Command" + (i-1).ToString(),
typeof(String));
i++;
}
}
//update the datatable in memory
DataRow row = dtMacros.Rows.Find(macroName);
if (row == null)
{
row = dtMacros.NewRow();
row[0] = macroName;
for (int i = 0; i < macro.Count; i++)
{
row[i+1] = macro;
}
dtMacros.Rows.Add(row);
}
else
{
row["MacroName"] = macroName;
for (int i = 1; i <= macro.Count; i++)
{
row = macro[i - 1];
}
}
adapterMacros.Update(dtMacros);
dtMacros.AcceptChanges();
macro.Clear();
}
The datatable in memory adds the new columns and rows as it should.
The database on disk will add the new rows and will update the
columns, but will not add the new columns.
Thanks for any help.
Regards,
Gary B
first load a datatable using:
private DataTable dtMacros = new DataTable();
private ArrayList macro = new ArrayList();
private SQLiteConnection cn;
private SQLiteDataAdapter adapterMacros;
cn = new SQLiteConnection("Data Source = irDatabase.db3");
SQLiteCommand commandMacros = new SQLiteCommand();
commandMacros.CommandText = "SELECT * FROM irMacros";
adapterMacros = new SQLiteDataAdapter(commandMacros.CommandText,
cn);
SQLiteCommandBuilder builderMacros = new
SQLiteCommandBuilder(adapterMacros);
adapterMacros.Fill(dtMacros);
dtMacros.PrimaryKey = new DataColumn[]
{ dtMacros.Columns["MacroName"] };
I am using an arraylist (macro) to store values for a new row - all
values are strings.
Later I update the data with the following code:
private void UpdateMacroDatabase(ArrayList macro, string macroName)
{
//Add datatable columns if needed for the datatable in
memory
if (dtMacros.Columns.Count <= macro.Count)
{
int i = dtMacros.Columns.Count;
while (i <= macro.Count)
{
dtMacros.Columns.Add("Command" + (i-1).ToString(),
typeof(String));
i++;
}
}
//update the datatable in memory
DataRow row = dtMacros.Rows.Find(macroName);
if (row == null)
{
row = dtMacros.NewRow();
row[0] = macroName;
for (int i = 0; i < macro.Count; i++)
{
row[i+1] = macro;
}
dtMacros.Rows.Add(row);
}
else
{
row["MacroName"] = macroName;
for (int i = 1; i <= macro.Count; i++)
{
row = macro[i - 1];
}
}
adapterMacros.Update(dtMacros);
dtMacros.AcceptChanges();
macro.Clear();
}
The datatable in memory adds the new columns and rows as it should.
The database on disk will add the new rows and will update the
columns, but will not add the new columns.
Thanks for any help.
Regards,
Gary B