[URGENT]Database to XML file asp.net

Posted by Write2varun under ASP.NET on 9/18/2013 | Points: 10 | Views : 1275 | Status : [Member] | Replies : 3
Hello,

I'm creating a Page in which, while Page_Load.

I'm taking the data from the database and writing it to the XML file.
My problem is I'm having a lot of data in the database so while creating the XML file it is taking a lot of time, which is not working for me.

I need to write the data in 2 to 3 seconds.
Please, I really need help to write the data.

I took the help from :
http://stackoverflow.com/questions/3523366/whats-the-best-way-to-write-and-download-xml-file-in-asp-net

Thanks in advance.




Responses

Posted by: Bandi on: 9/18/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
I doesn't have exact solution.. I can suggest one workaround...
1) We should process the data batch-wise in the case of large volume of data...
i.e.
Use limit in your query to fetch only limited records and keep it in your session variable. once you reach the exhaustion limit on either side (say 10 in <next> or 1 in <prev>), then query the next 10 records.

So user will have only the limit of records in session to view and querying the whole load information is avoided
2)
And do you have proper indexes on tables? if there is indexes on table columns it might help you in the process of speed loading

Refer http://forums.asp.net/t/1810340.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Write2varun, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Write2varun on: 9/18/2013 [Member] Starter | Points: 25

Up
0
Down
hello, your reply is really helpful but please help me i don't know how to do paging while selecting the data from sql server

Write2varun, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 9/18/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Export_Gridview_to_Xml._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:Button ID="btnsave" runat="server" onclick="btnsave_Click"
Text="Save to Xml" />
</div>
</form>
</body>
</html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Export_Gridview_to_Xml
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;

protected void BindGrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
con.Close();
ds = new DataSet();
sqlda.Fill(ds, "employee");
GridView1.DataSource = ds;
GridView1.DataMember = "employee";
GridView1.DataBind();
}

protected void btnsave_Click(object sender, EventArgs e)
{
BindGrid();
ds.WriteXml("d:\\employee.xml");
Response.Write("Records saved as xml");
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}


}
}


If this post helps you mark it as answer
Thanks

Write2varun, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response