I am inserting data in one table(e.g. InsertTable) & updating another table(e.g. UpldTable) in a loop on a button click.(say loop of 2500 iterations)
I want to retrieve updated value from UpldTable. & display it on same page.
And on timer_tick event i display value from UpldTable after every 2 seconds.
but Value is displayed only when all the writes & updates are done. I want to display updated value after every 2 seconds.
here is the code which i tried
private void ParseCommand(string command, string uid, string ivr, string sort, string service)
{
string SERVICE_ID = "", MOBILE = "", DUE_DATE = "", BILLED_OUTSTD = "", CITY = "";
try
{
if (command != "timeout" || command != "-1")
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(command);
XmlNodeList cnn = xmldoc.DocumentElement.ChildNodes;
XmlNodeList NodeListMessage = xmldoc.DocumentElement.GetElementsByTagName("RESULT");
XmlNodeList NodeListMessage1 = xmldoc.DocumentElement.GetElementsByTagName("SERVICE_DETAILS");
string ResultStatus = "", str_result_status = "", str_service_id = "";
foreach (XmlNode nodeInfo in NodeListMessage)
{
ResultStatus = nodeInfo["STATUS"].InnerText;
if (ResultStatus == "SUCCESS")
{
str_service_id = Convert.ToString(nodeInfo["SERVICE_ID"].InnerText);
SERVICE_ID = Convert.ToString(nodeInfo["SERVICE_ID"].InnerText);
}
}
if (ResultStatus == "SUCCESS")
{
foreach (XmlNode nodeInfo in NodeListMessage1)
{
SERVICE_ID = Convert.ToString(nodeInfo["SERVICE_ID"].InnerText);
MOBILE = Convert.ToString(nodeInfo["MOBILE"].InnerText);
DUE_DATE = Convert.ToString(nodeInfo["LST_PAY_DATE"].InnerText);
BILLED_OUTSTD = Convert.ToString(nodeInfo["OUTSTANDING_BAL"].InnerText);
CITY = Convert.ToString(nodeInfo["CITY"].InnerText);
con2.Open();
string insertText = "insert into siebel_return_result(ServiceID, ReqUserID,ReqCollectionType, ReqCollectionSorting, Result, RetUserID, RetMobile, RetDueDate, RetBillOutstanding, RetCity) " +
"values ('" + service + "','" + uid + "','" + ivr + "','" + sort + "','" + ResultStatus + "','" + SERVICE_ID + "','" + MOBILE + "','" + DUE_DATE + "','" + BILLED_OUTSTD + "','" + CITY + "')";
SqlCommand cmdInsertResult = new SqlCommand(insertText, con2);
cmdInsertResult.ExecuteNonQuery();
string updtCount = "update upldTable set isnull(count,0)= count+ 1";
SqlCommand cmdUpdtCount = new SqlCommand(updtCount, con2);
cmdUpdtCount.ExecuteNonQuery();
con2.Close();
}
}
}
}
catch (Exception ex)
{
Response.Write(SERVICE_ID + " : Error 1" + ex.Message + " <br>" );
}
}
this function called on button click
& on timer_tick event counter is called
public void Counter()
{
try
{
con.Open();
string strCount = "select count from upldTable WITH (NOLOCK)";
SqlCommand cmdCount = new SqlCommand(strCount, con);
int count = Convert.ToInt16(cmdCount.ExecuteScalar());
string strTotal = "SELECT COUNT(*) FROM pload_Data";
SqlCommand cmdTotal = new SqlCommand(strTotal, con);
int Total = Convert.ToInt16(cmdTotal.ExecuteScalar());
if (Total != 0)
{
double percent = (count / Total) * 100;
percent = Math.Round(percent, 2);
lblCounter.Text = "[ Data Status : " + count.ToString() + " of " + Total.ToString() + " ]<BR/>";
if (Total == count)
{
lblProgress.Text = "Upload Complete";
}
if (count == 0)
{
lblCounter.Text = "";
}
}
else if (Total == count)
{
lblCounter.Text = "";
}
con.Close();
}
catch (Exception ex)
{
lblProgress.Text = "Error : " + ex.Message;
}
}
following is .aspx file code
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
<asp:AsyncPostBackTrigger ControlID="btnSynch" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnDelete" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnQueue" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnExport" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="lblProgress" runat="server"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="3000" ontick="Timer1_Tick" Enabled="true">
</asp:Timer>
<asp:Label ID="lblCounter" runat="server"></asp:Label>
<asp:HyperLink ID="linkProgress" runat="server" Visible="False">Click here to see the progress</asp:HyperLink>
<br />
<asp:Label ID="lblMsg" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="lblError" runat="server" ForeColor="#FF3300"></asp:Label>
<br />
<asp:GridView ID="grdData" runat="server" CellPadding="4"
EnableModelValidation="True" ForeColor="#333333" GridLines="None"
PageSize="100" Width="100%">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>