Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (1 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
C#
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
Updated 11-Dec-17 3:19am
v2

1 solution

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());
				}
			}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900