Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is wrong with my program logic
    text
    copied!<p>Please help me find the defect in my logic. I have two variables named "prev" and "next"...What i am basically doing is reading the data from my database every 5s and printing it out using Websync server if next and prev are NOT equal. I have two rows in my database . It looks like </p> <pre><code>ID 8 10 </code></pre> <p>Here is the link to the code <a href="http://pastebin.com/Hb3eH2Qv" rel="nofollow">http://pastebin.com/Hb3eH2Qv</a></p> <p>When i run my program, i get the result as </p> <pre><code>8 10 8 10 8 10 8 10 8 10 8 10 </code></pre> <p>..... (so on)</p> <p>But, the result should be just </p> <pre><code>8 10 </code></pre> <p>I dont know how <code>8 10 8 10</code> appears. Data gets concatenated twice. </p> <p>NOTE: You can just see the code in <code>PublishLoop()</code> function </p> <pre><code>private void PublishLoop() { String prev=String.Copy(""); String next=String.Copy(""); String ConnectionString = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString(); SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand command = connection.CreateCommand(); command.CommandText = "select ID from Tab1"; command.Notification = null; while (Running) { connection.Open(); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { StreamWriter sw1 = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\next.txt"); while ((reader.Read())) { //Response.Write(reader[0].ToString()); next = String.Concat(next,reader[0].ToString()); sw1.WriteLine(next); } sw1.Close(); if (!prev.Equals(next)) { Publisher publisher = new Publisher(new PublisherArgs { DomainKey = "c80cb405-eb77-4574-9405-5ba51832f5e6", DomainName="localhost" }); Publication publication = publisher.Publish("/test", JSON.Serialize(next)); if (publication.Successful == true) { StreamWriter sw = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\error123.txt"); sw.WriteLine("success"); sw.WriteLine(next); sw.Close(); } else { StreamWriter sw = new StreamWriter("C:\\Users\\Thothathri\\Desktop\\error123.txt"); sw.Write("failed"); sw.Close(); } prev = String.Copy(next); next = String.Copy(""); } } Thread.Sleep(5000); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload