Click here to Skip to main content
15,918,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to implement the status of a current logged in user in an WPF application. I can read from the database and set that value once , but i need it to keep updating. So for example when a user is online, and he changes to busy. The value would be online, but once it changed on the database to busy , the value would update to busy too.

for example:

C#
connection = new MySqlConnection(connectionString);
  Query = "SELECT status FROM Accounts WHERE username=@username";
  connection = new MySqlConnection(connectionString);

  MySqlCommand command = new MySqlCommand(Query, connection);
  command.CommandType = System.Data.CommandType.Text;
  command.Parameters.AddWithValue("@username", thedesiredusername);
  connection.Open();
  MySqlDataReader dataReader = command.ExecuteReader();

  while (dataReader.Read())
  {
     string userstatus = dataReader.GetString("status");
  }


This would set the userstatus value once. How can i get it to do something like this:
C#
connection = new MySqlConnection(connectionString);
Query = "SELECT status FROM Accounts WHERE username=@username";
connection = new MySqlConnection(connectionString);

MySqlCommand command = new MySqlCommand(Query, connection);
command.CommandType = System.Data.CommandType.Text;
command.Parameters.AddWithValue("@username", thedesiredusername);
connection.Open();
MySqlDataReader dataReader = command.ExecuteReader();

while (dataReader.Read())
{
   //keep doing:
   if (userstatus != dataReader.GetString("status"))
   {
     string userstatus = dataReader.GetString("status");
   }

}


Thanks in advance!

What I have tried:

i've tried the above . Also tried the TableDependency Package but for some reason my connectionstring didn't work on that.
Posted
Updated 25-Feb-18 19:27pm
Comments
saimanisha 26-Feb-18 1:24am    
once you are updating online how you are displaying as online the same way you update busy too.
where you have doubt exactly

1 solution

when user selects to keep busy then immediately you write code for updating it into database and then override the online with busy in ui.
give notification to user after certain time do you want to keep online or busy yet..
 
Share this answer
 
Comments
Schooka 27-Feb-18 12:37pm    
but i don't just need it for the user i need it when friends are displayed too : for example lets say in teh database there is a user called beans. beans has a friend called test . when beans loggs in and goes to friends he will see that test is online but once test is goes offline he will still see beans is online . i need it to keep updating so whenever test goes offline beans needs to see that test just went offline .
saimanisha 28-Feb-18 5:22am    
see set a timer set interval as 10 sec or whatever as per your requirement.for every few sec make it refresh .like when time is elapsed then it hits to the code where you are writing to fetch data who is online .
this one works well.if you think there will be any drawbacks if you use this .let me know.i ll try to get new idea which overcome those drawbacks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900