Hi guys, I'm really hoping that someone can help me...
I have 3 datasets. One that will contain the initial information when I open up the database; one that will pull in information afterwards; and a 3rd to show the changes that have occured since merging #1 and #2.
Now when I'm testing this data, it seems that HasChanges always returns true.
Am I invoking something wrong? Am I not using AcceptChanges and HasChanges properly??
Here is what I have
[code]
using System;
using System.Data;
using System.Collecti ons.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Seri alization;
using System.Text;
using MySql.Data;
using MySql.Data.MySq lClient;
namespace MySQL
{
class Program
{
static void Main(string[] args)
{
//***Load the Configuration Data***//
Configuration myConfig = new Configuration() ;
myConfig.Config urationLoader() ;
String MyConnString =
myConfig.connec tion_info.datab ase[1].connection_str ing;
//-----Define the MySQL Connection
MySqlConnection connection = new MySqlConnection (MyConnString);
//---Take the inital snap shot
Snapshot snapshot = new Snapshot();
snapshot.intial _snap_shot(myCo nfig, connection);
//--Enter the loop checking for new data--//
while (true)
{
Console.WriteLi ne("Press enter to start looking for new data");
Console.ReadLin e();
snapshot.merge_ snap_shot(myCon fig, connection);
//Merge Data
snapshot.Merge( );
}
}
}
}
using System;
using System.Data;
using System.Collecti ons.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Seri alization;
using System.Text;
using MySql.Data;
using MySql.Data.MySq lClient;
namespace MySQL
{
class Snapshot
{
private DataSet primary_ds = new DataSet();
private DataSet merge_ds = new DataSet();
private DataSet diff_ds = new DataSet();
public void intial_snap_sho t(Configuration myConfig , MySqlConnection conn)
{
for (int i = 0; i < myConfig.config uration.schedul ing.OutgoingDat a.Tables1.Lengt h; i++)
{
Console.WriteLi ne("Table Count : " + primary_ds.Tabl es.Count.ToStri ng());
MySqlDataSet(my Config.configur ation.schedulin g.OutgoingData. Tables1[i].name, conn);
Console.WriteLi ne("Row Count For Table : " + i.ToString() + " : "
+ primary_ds.Tabl es[i].Rows.Count.ToS tring());
}
}
public void merge_snap_shot (Configuration myConfig, MySqlConnection conn)
{
for (int i = 0; i < myConfig.config uration.schedul ing.OutgoingDat a.Tables1.Lengt h; i++)
{
Console.WriteLi ne("Table Count : " + merge_ds.Tables .Count.ToString ());
MySqlDataSet2(m yConfig.configu ration.scheduli ng.OutgoingData .Tables1[i].name, conn);
Console.WriteLi ne("Row Count For Table : " + i.ToString() + " : "
+ merge_ds.Tables[i].Rows.Count.ToS tring());
}
}
public void MySqlDataSet(St ring TableName, MySqlConnection conn)
{
MySqlDataAdapte r adapter = new MySqlDataAdapte r("SELECT * FROM " + TableName, conn);
adapter.Missing SchemaAction = MissingSchemaAc tion.AddWithKey ;
adapter.Fill(pr imary_ds);
primary_ds.Tabl es[primary_ds.Tabl es.Count - 1].TableName = TableName;
primary_ds.Tabl es[primary_ds.Tabl es.Count - 1].AcceptChanges( );
}
public void MySqlDataSet2(S tring TableName, MySqlConnection conn)
{
MySqlDataAdapte r adapter = new MySqlDataAdapte r("SELECT * FROM " + TableName, conn);
adapter.Missing SchemaAction = MissingSchemaAc tion.AddWithKey ;
adapter.Fill(me rge_ds);
merge_ds.Tables[merge_ds.Tables .Count - 1].TableName = TableName;
}
public void Merge()
{
primary_ds.Merg e(merge_ds, true);
if (primary_ds.Has Changes())
{
Console.WriteLi ne("Changes Exist");
primary_ds.Acce ptChanges();
merge_ds.Accept Changes();
}
else
{
Console.WriteLi ne("No Changes");
}
}
}
}