Good morning Vickey,
Thank you so much for your replay,
I did us the code but not exactly because I have around 90 tables in sdf database file. However, I got the following exception
(" Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information").
I am going to post my code here including your code.
Please take a look at it and let me know. I am really stuck. I tried to explain the code.
Thanks a lot
protected void Merge_Datasets()
{
//connection string to the first sdf file selected by the user
string dbConString = (connString)
DataSet dataset = new DataSet("dataset");
//Data table to hold the names of the tables in the sdf database
dataset.Tables.Add("Names");
SqlCeConnection connection = new SqlCeConnection(dbConString);
SqlCeDataAdapter CeAdapter = new SqlCeDataAdapter("selecttable_name from information_schema.tables", connection);
//loading the names of the tables
CeAdapter.Fill(dataset.Tables["Names"]);
//Dataset to hold the data from first sdf database
DataSet firstDataset = new DataSet("firstDataset");
//Loop to build sql query and populate every table in the dataset from te sdf file
for (int i = 0; i < dataset.Tables["Names"].Rows.Count; i++)
{
string tableName =dataset.Tables["Names"].Rows[i]["table_name"].ToString();
firstDataset.Tables.Add(tableName);
CeAdapter = new SqlCeDataAdapter("select * from " +tableName, connection);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(CeAdapter);
CeAdapter.Fill(firstDataset.Tables[tableName]);
}
firstDataset.AcceptChanges();
//Connection string to the second sdf database
string sourceConn =( connString)
//Repeat the same steps to populate the second dataset
DataSet sourceDataset = new DataSet("sourceDataset");
sourceDataset.Tables.Add("Table_Name");
connection = new SqlCeConnection(sourceConn);
CeAdapter = new SqlCeDataAdapter("select table_name from information_schema.tables", sourceConn);
CeAdapter.Fill(sourceDataset.Tables["Table_name"]);
//Dataset to hold the data from the second sdf database
DataSet secondDataset = new DataSet("secondDataset");
for (int i = 0; i <sourceDataset.Tables["Table_name"].Rows.Count; i++)
{
string tableName =sourceDataset.Tables["Table_name"].Rows[i]["table_name"].ToString();//get
the table name to be used in the select statement
secondDataset.Tables.Add(tableName);
CeAdapter = new SqlCeDataAdapter("select * from " +tableName, connection);
CeAdapter.Fill(secondDataset.Tables[tableName]);
}
//**I added this loop from your post, but I think the merge function does the same thing
//for(int j = 0; j<secondDataset.Tables[80].Rows.Count;j++)
//{
// DataRow NewR = firstDataset.Tables[80].NewRow();
// NewR.ItemArray = secondDataset.Tables[80].Rows[j].ItemArray;
// firstDataset.Tables[80].Rows.Add(NewR);
//}
secondDataset.AcceptChanges();
//calling the merge function and just doing it on one table for now
firstDataset.Tables[80].Merge(secondDataset.Tables[80]);
firstDataset.AcceptChanges();
//diplaying the data in a datagrid to make sure the dataset has the merged data; and it is working until here
RadGrid1.DataSource = firstDataset.Tables[80];
RadGrid1.DataBind();
//trying to update the sdf file so i am reassigning the connection to the adapter; x to see how many records got affected
connection = new SqlCeConnection(dbConString);
CeAdapter = new SqlCeDataAdapter(null, connection);
SqlCeCommandBuilder cb3 = new SqlCeCommandBuilder(CeAdapter);
int x = CeAdapter.Update(firstDataset, "visit");// function returning zero
}