Click here to Skip to main content
13,599,044 members
Rate this:
 
Please Sign up or sign in to vote.
Hi,
when I tried to export data upto 65000 records into rdlc it is working fine but if it exceeds 65000 records then i am getting out of memory exception
I need to export bulk data into rdlc or csv file using .net is there any alternate method is there to achieve this




Thanks

What I have tried:

I am able generate rdlc if the data is less
Below is the code I am using to generate rdlc
using (SqlConnection con = new SqlConnection(sqlConnectionString))
                                {
                                    con.Open();
                                    SqlCommand cmd = new SqlCommand("select query from report_query where query_id=@id", con);
                                    cmd.Parameters.AddWithValue("@id", id);
                                    string query = cmd.ExecuteScalar().ToString();

                                    cmd.CommandText = query;
                                    cmd.CommandTimeout = 0;
                                    dt.TableName ="ReportTable";
                                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                                    da.Fill(dt);
                                    con.Close();
                                }
                                
                                rvDataViewer.LocalReport.ReportPath = "Reports/ReportEX.rdlc";
                                rvDataViewer.LocalReport.DataSources.Clear();
                                rvDataViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportEX", dt));
                                rvDataViewer.DataBind();
                                rvDataViewer.LocalReport.Refresh();
Posted 11-Dec-17 1:20am
Updated 11-Dec-17 3:19am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Comma separated file:

using (SqlConnection con = new SqlConnection(sqlConnectionString))
			{
				con.Open();
				SqlCommand cmd = new SqlCommand("select query from report_query where query_id=@id", con);
				cmd.Parameters.AddWithValue("@id", id);
				string query = cmd.ExecuteScalar().ToString();
				cmd.CommandText = query;
				cmd.CommandTimeout = 0;
								 
				SqlDataReader rReader = cmd.ExecuteReader();
				string reportName = string.Format("ReportEX_{0}.csv" , id);

				while(rReader.Read())
				{
					StringBuilder oneRow = new StringBuilder();
					for(int ii = 0; ii < rReader.FieldCount; ii++)
					{
						oneRow.AppendFormat("{0},", rReader[ii]);
					}
					oneRow.Append(Environment.NewLine);
					File.AppendAllText(reportName, oneRow.ToString());
				}
			}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.180621.3 | Last Updated 11 Dec 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100