Page 1 of 1

Table/DataBand with CSV-String from SQL-Database

Posted: Wed Jul 13, 2016 8:22 am
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

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

Posted: Wed Jul 13, 2016 10:15 am
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.

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

Posted: Wed Jul 13, 2016 10:38 am
by stani8048
Thank you Alexksey!

How do I do this?
Is there a manual or example code?

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

Posted: Thu Jul 14, 2016 12:47 pm
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.

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

Posted: Wed Jul 20, 2016 12:58 pm
by stani8048
Thank you, Aleksey

I would prefer to make it in the designer with scripts.

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

Posted: Fri Jul 22, 2016 3:03 pm
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.