1
Answer

data continuously inserted in table

scropio gurl

scropio gurl

8y
310
1
I try to send data in table when time exceed over 5 mint data is inserted successfully but data insert multiple times i want to submit data only one time
i.e. only one row insert for 1 number
this is what i try
  1. if (timediff.TotalMinutes > 5)  
  2. {  
  3. DataClasses1DataContext db = new DataClasses1DataContext();  
  4. var u = db.tbl_urgent_contacts;  
  5. foreach (var a in u)  
  6. {  
  7. tbl_OutBox tb = new tbl_OutBox();  
  8. tb.FromSIM_No = a.SimNo;  
  9. tb.ToSIM_No = a.SimNo;  
  10. tb.ToText = "Check abc";  
  11. tb.Reply = "NA";  
  12. tb.Response = "NA";  
  13. tb.RegNo = "NA";  
  14. tb.Datetd = DateTime.Now;  
  15. tb.FFID = "NA";  
  16. tb.UserId = "You";  
  17. tb.FromText = "Check abc";  
  18. db.tbl_OutBoxes.InsertOnSubmit(tb);  
  19. db.SubmitChanges();  
  20. }  
  21. }  
Answers (1)
0
Akshay Phadke

Akshay Phadke

NA 16.7k 1.3m 8y
You had written for loop there whenever it is called it will insert data multiple times . make changes in your code write these line
db.tbl_OutBoxes.InsertOnSubmit(tb);
db.SubmitChanges();
after you loop ends . It will insert data only on time .
Initially you had written those lines inside loop , loop keeps on inserting data when the condition is true in If it will insert data only Once