c# - Show records processed to user while fetching records from DB and writing to a text file -


i trying fetch records sql db , writing them text file when user clicks on button. want is, no. of records shown user during process. if there 10000 records (say), when user clicks on button, there should progress showing "no. of records written: 1,2,3.... " , on. means user must able see how many records have been written. here code, plz edit desired thing.

<form id="form1" runat="server"> <div>     <asp:scriptmanager id="scriptmanager" runat="server" enablepartialrendering="true">     </asp:scriptmanager>     <asp:timer runat="server" id="timer1" interval="1000" enabled="false" ontick="timer1_tick" />     <asp:updatepanel id="updatepanell" runat="server" updatemode="always">         <triggers>             <asp:asyncpostbacktrigger controlid="timer1" eventname="tick" />         </triggers>         <contenttemplate>             <asp:textbox id="label1" runat="server" textmode="multiline" height="250px" width="800px"/>         </contenttemplate>     </asp:updatepanel>     <asp:button id="button2" runat="server" text="insert records2"          onclick="button2_click" />     <asp:updateprogress id="updateprogress1" associatedupdatepanelid="updatepanell" runat="server">         <progresstemplate>             update in progress……..         </progresstemplate>     </asp:updateprogress> </div> </form> 

and here code behind:

protected void button2_click(object sender, eventargs e)     {         string filename = @"c:\insert\myfile.txt";         string cs = "data source=machinename;initial catalog=testdb;integrated security=sspi;persist security info=true;";         string sql = "select id employee";          if (file.exists(filename))             file.delete(filename);         using (streamwriter writer = new streamwriter(filename))         {             sqlconnection conn = new sqlconnection(cs);             conn.open();             sqlcommand command = new sqlcommand(sql, conn);             var reader = command.executereader();             while (reader.read())             {                 stringbuilder mydata = new stringbuilder();                 mydata.append(reader["id"].tostring());                 writer.writeline(mydata.tostring());             }             conn.dispose();             conn.close();             writer.close();         }     } 


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -