problem in retrieving data from DB
1. this is test code which i modified, but its seems not working, let me know the proper solution to retrieve data from DB.
2. Is that enough to write only DataAdapter and client, else i have to write MetaDataAdapter, DataAdapter and client.
Code:
public class MyDataAdapter : IDataProvider
{
private IItemEventListener listener;
private volatile bool go;
private DataTable dt;
private SqlConnection conn;
private SqlCommand comm;
public MyDataAdapter()
{
try
{
conn = new SqlConnection("Data Source=(local);Database=Northwind; Integrated Security=true;");
comm = new SqlCommand("Select * from Orders", conn);
conn.Open();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex);
throw new DataProviderException(ex.Message.ToString());
}
}
public void Init(IDictionary parameters, string configFile)
{
}
public bool IsSnapshotAvailable(string itemName)
{
return false;
}
/// <summary>
/// Used to receive a reference to the server's listener
/// that will be used to inject events.
/// </summary>
/// <param name="eventListener"></param>
public void SetListener(IItemEventListener eventListener)
{
listener = eventListener;
}
public void Subscribe(string itemName)
{
if (itemName.Equals("myData"))
{
Thread t = new Thread(new ThreadStart(Run));
t.Start();
}
}
public void Unsubscribe(string itemName)
{
if (itemName.Equals("myData"))
{
go = false;
}
}
public void Run()
{
go = true;
while (go)
{
try
{
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
IDictionary eventData = new Hashtable();
eventData.Add("OrderID", dr[0]);
eventData.Add("UnitPrice", dr[1]);
eventData.Add("Quantity", dr[2]);
eventData.Add("Discount", dr[3]);
listener.Update("myData", eventData, false);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
conn.Close();
}
}
}
}
how to display newly added record in webclient
Now i am able to display the data in webclient and if i change value in db that automatically reflecting in webclient. In INIT method i am retrieving all the record in 1shot and storing in dataTable, and then showing in webclient, if change any value from backend its also reflecting the page with updated value, now if i added new record instead of modifying/updating existing record that should also be subscribed in webclient.
What are the changes that need to done and where exactly i have to write the code in which event.