Data Binding to Independent Data Table

Weste

Member
Joined
Feb 4, 2005
Messages
14
Here is what I am trying to do. I am using ASP.NET 2.0. I have created a data set called Stocks data table called Data and put it in the App_Code folder. I am filling the data table from data in a csv file located on the web. I am populating the data table with the following code. This code works because I checked the record count and it shows 21 records for the Data data table.

public static DataSet Convert()
{
WebClient Client = new WebClient();
Stream myStream = Client.OpenRead("http://mysite.com/table.csv");
StreamReader myStreamReader = new StreamReader(myStream);

Stocks myStocks = new Stocks();

string line = myStreamReader.ReadLine();
string allData = myStreamReader.ReadToEnd();

string[] rows = allData.Split("\r\n".ToCharArray());

foreach (string r in rows)
{
string[] items = r.Split(",".ToCharArray());
myStocks.Tables["Data"].Rows.Add(items);
}

return myStocks;
}

I am trying to bind the data in this table to a report. I added a report to my project and selected the fields from the data table. I then added a ReportViewer control to the web form. I
 
You pretty much have it, but instead of using an ObjectDataSource you can just add a data source to the report at runtime:
Code:
ReportDataSource ds = new ReportDataSource();
ds.Value = Convert().Data;

ReportViewer1.LocalReport.DataSources.Add(ds);
 
Back
Top