Table/DataBand with CSV-String from SQL-Database

Stimulsoft Reports.NET discussion
Post Reply
stani8048
Posts: 5
Joined: Wed Jul 13, 2016 8:11 am

Table/DataBand with CSV-String from SQL-Database

Post by stani8048 »

Hello,

I've got one problem.
I've got a report with a SQL-query, which includes one field, which is filled with a CSV-string. Usually we build our reports in the designer, but in this case it is not possible.

Now this CSV-string should be displayd as a table or databand within the report. So I've tried to add this in the Code-tab.
I've got this c# code so far:

Code: Select all

		public void CSVimport(string csv)
		{
			MessageBox.Show(csv); // test if the csv-string is here
			DataTable dt = new DataTable("CSVdataset");
	
			string[] lines = csv.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
				
			for(int i = 0;i < lines[0].Split(';').Length;i++)
			{
				dt.Columns.Add(lines[0].Split(';')[i]);
			}
				
			foreach (string line in lines)
			{
				string[] cells = line.Split(';');
					
				DataRow dr = dt.NewRow();
				//for (int i = 0; i < cells.Length; i++)
				//{
				//	dr[i] = cells[i];
				//}
					
				dt.Rows.Add(cells);
			}
				
			DataSet ds = new DataSet("CSVdataset");
	
			ds.Tables.Add(dt);
				
			this.DataBand2.DataSourceName = "CSVdataset"; // data is not shown in the report
			
			StringWriter sw = new StringWriter();
			ds.WriteXml(sw);
			string result = sw.ToString();
			MessageBox.Show(result); // just to test it, if the csv.string is in the dataset
				
			//this.Render();
			
			//return ds;
		}
Can anyone help me to solve this?
Thank you!

KR
Alex

PS: I use Stimulsoft Reports.Net Version 2013.2.1700 from 19 September
.Net Framework v2.0.50727
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Table/DataBand with CSV-String from SQL-Database

Post by Alex K. »

Hello,

Unfortunately, it is not possible directly in the designer.

In this case, you need to prepare this additional table in your code and register to the designer main table and additional.

Thank you.
stani8048
Posts: 5
Joined: Wed Jul 13, 2016 8:11 am

Re: Table/DataBand with CSV-String from SQL-Database

Post by stani8048 »

Thank you Alexksey!

How do I do this?
Is there a manual or example code?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Table/DataBand with CSV-String from SQL-Database

Post by Alex K. »

Hello,

We need some additional time to prepare a sample for you.
Also, there is a solution make it in the designer with scripts.

Thank you.
stani8048
Posts: 5
Joined: Wed Jul 13, 2016 8:11 am

Re: Table/DataBand with CSV-String from SQL-Database

Post by stani8048 »

Thank you, Aleksey

I would prefer to make it in the designer with scripts.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Table/DataBand with CSV-String from SQL-Database

Post by Alex K. »

Hello,

In this case, you can add new data source as new "Data from DataSet, DataTable", add necessary columns. And then in the AfterPrint event of the main datanamd use the following code:

Code: Select all

var csvString = DataSourceName.ColumnName;
DataTable dt = new DataTable("CSVdataset");
string[] lines = csvString.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
for (int i = 0; i < lines[0].Split(';').Length; i++)
{
    dt.Columns.Add(lines[0].Split(';')[i]);
}
foreach (string line in lines)
{
    string[] cells = line.Split(';');
    DataRow dr = dt.NewRow();
    dt.Rows.Add(cells);
}
DataSource1.DataTable = dt;
Thank you.
Attachments
ReportCSV.mrt
(8.19 KiB) Downloaded 175 times
Post Reply