Click here to Skip to main content
15,884,094 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hii all i have a winform in which m trying to update data from tally to server
database.any change in tally gets reflected to server.i am doing all this through threading.now i want to show the data in datagrid from server on clicking the menu.
Its working fine and shows data in datagrid but sometimes it does not show data in
grid.i cant figure out the problem.tell me where m i wrong....!!

C#
if (thrd != null)
{
   if (thrd.ThreadState == ThreadState.Stopped || thrd.ThreadState == ThreadState.WaitSleepJoin || thrd.ThreadState == ThreadState.Aborted)
   {
      thrd = new Thread(new ThreadStart(startprocess));
      thrd.Start();
   }
   else
   {
      startprocess();
   }
}
else
{
   thrd = new Thread(new ThreadStart(startprocess));
   thrd.Start();
   }

in startproceess m comparing the data of tally and server n if any change is made to tally data it gets updated
through startprocess.this is background process.now at front end if i clcik on menu stock item.it shows data in grid.
but the data is sometimes available sometimes not.
C#
string query = "select * from Product_Master where Compid=(select Companyid from Company_Master where Companyname='" + txtuserid.Text + "')";
           
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
da.Fill(dt);
                
gridproduct.DataSource = dt;
              
panel4.Visible = true;
Posted
Updated 7-Jul-11 16:20pm
v3
Comments
[no name] 28-Jun-11 8:17am    
"I have a winform..." and "threading in asp.net"

Which is it? Clarify your question
R. Giskard Reventlov 28-Jun-11 9:12am    
Confused think is he I
Vivek Krishnamurthy 28-Jun-11 9:21am    
is that a typo... winform or webform ?
walterhevedeich 7-Jul-11 23:10pm    
Probably not a typo since it was seen at least 2 times. Misinformed might be a better term.

1 solution

As you said ASP.NET, I assume you mean webforms. You can't be starting threads in ASP.NET, because your code only runs to generate a page, and it won't wait for a thread to run.
 
Share this answer
 
Comments
fjdiewornncalwe 7-Jul-11 22:52pm    
That thought came to me as well, which is why I came back to this question. Glad I'm not the only one who saw that. :)
Christian Graus 7-Jul-11 23:00pm    
It's a common mistake made by people trying to do good work, without understanding how ASP.NET works. I've seen it asked here, many times.

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