how to dynamic bind data in asp.net

edited June 2012 in FastReport .NET
hi guys:
i have a difficulty to dynamic data in web form. the code see below:
public partial class PuchasePrint : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (wrptPuchasePrint.ReportFile == String.Empty)
{
wrptPuchasePrint.ReportFile = Server.MapPath("/PuchasePrint.frx");
wrptPuchasePrint.Prepare();
}
}

protected void wrptPuchasePrint_StartReport(object sender, EventArgs e)
{
FastReport.Report FReport = (sender as FastReport.Web.WebReport).Report;
RegisterData(FReport);
}

private void RegisterData(FastReport.Report FReport)
{
string beginDate = txtBeginDate.Text, endDate = txtEndDate.Text;

DataSet dtPushasePrint = GetDataSet();//ServiceFactory.GetInstance().GetOrderInfoService().GetPuchasePrint(beginDate, endDate);
wrptPuchasePrint.Report.RegisterData(dtPushasePrint, "Table");
//?§?»??????®???¦????°?¦???®?????°?¦????°?¦???®????????????
DataBand band = FReport.FindObject("Data1") as DataBand;
band.DataSource = FReport.GetDataSource("Table");
}

protected void btnQuery_Click(object sender, EventArgs e)
{
FastReport.Data.DataSourceBase dsb = wrptPuchasePrint.Report.GetDataSource("Table");
wrptPuchasePrint.Report.SetParameterValue("@BeginDate";, txtBeginDate.Text);
wrptPuchasePrint.Report.SetParameterValue("@EndDate";, txtEndDate.Text);
wrptPuchasePrint.ReportFile = Server.MapPath("/PuchasePrint.frx");
wrptPuchasePrint.Prepare();

}

private DataSet GetDataSet()
{
string connectionString = @Data Source=***.***.***.***;Initial Catalog=******;Integrated Security=False;Persist Security Info=False;User ID=*****;Password=********; Connect Timeout=300;
DataSet dataSet;
string beginDate = txtBeginDate.Text;
string endDate = txtEndDate.Text;
using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
// adapter.TableMappings.Add("Table", "t_Users");
SqlCommand command = new SqlCommand(
string.Format("SELECT FProductQty,FProductSKU,FProductName,FOrderId FROM t_OrderDetail WHERE FOrderId BETWEEN '{0}' and '{1}'", beginDate, endDate),
connection);
command.CommandType = CommandType.Text;
adapter.SelectCommand = command;
dataSet = new DataSet("t_OrderDetail");
adapter.Fill(dataSet);
}
return dataSet;
}
}


the FR CODE:
<?xml version="1.0" encoding="utf-8"?>
<Report ScriptLanguage="CSharp" TextQuality="Regular" ReportInfo.Created="06/02/2012 12:54:12" ReportInfo.Modified="06/04/2012 13:47:52" ReportInfo.CreatorVersion="1.8.47.0">
<Dictionary>
<TableDataSource Name="Table" ReferenceName="Table" DataType="System.Int32" Enabled="true">
<Column Name="FProductQty" DataType="System.Decimal"/>
<Column Name="FProductSKU" DataType="System.String"/>
<Column Name="FProductName" DataType="System.String"/>
<Column Name="FOrderDate" DataType="System.DateTime"/>
</TableDataSource>
</Dictionary>
<ReportPage Name="Page1" RawPaperSize="9" FirstPageSource="15" OtherPagesSource="15">
<ReportTitleBand Name="ReportTitle1" Width="718.2" Height="89.3">
<TextObject Name="Text14" Width="718.2" Height="37.8" Text="For Test" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 16pt, style=Bold"/>
<TextObject Name="Text13" Top="28.35" Width="718.2" Height="37.8" Text="Bill Type" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 12pt, style=Bold"/>
<TextObject Name="Text11" Left="472.5" Top="70.4" Width="94.5" Height="18.9" Text="Print time:" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 10pt"/>
<TextObject Name="Text12" Left="567" Top="70.4" Width="151.2" Height="18.9" Text="[Date]" Font="???®????¤?????, 9pt"/>
</ReportTitleBand>
<PageHeaderBand Name="PageHeader1" Top="93.3" Width="718.2" Height="18.9">
<TextObject Name="Text2" Left="46.6" Width="103.95" Height="18.9" Border.Lines="All" Text="ProductSKU" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 9pt"/>
<TextObject Name="Text4" Left="150.55" Width="236.25" Height="18.9" Border.Lines="All" Text="ProductName" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 9pt"/>
<TextObject Name="Text6" Left="386.35" Width="66.15" Height="18.9" Border.Lines="All" Text="ProductQty" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 9pt"/>
<TextObject Name="Text17" Width="47.25" Height="18.9" Border.Lines="All" Text="???????????·" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 9pt"/>
</PageHeaderBand>
<DataBand Name="Data1" Top="116.2" Width="718.2" Height="28.35" DataSource="Table">
<TextObject Name="Text1" Left="46.6" Width="103.95" Height="28.35" Border.Lines="All" Text="[Table.FProductSKU]" VertAlign="Center" Font="???®????¤?????, 9pt"/>
<TextObject Name="Text3" Left="150.55" Width="236.25" Height="28.35" Border.Lines="All" Text="[Table.FProductName]" VertAlign="Center" Font="???®????¤?????, 9pt"/>
<TextObject Name="Text5" Left="386.35" Width="66.15" Height="28.35" Border.Lines="All" Text="[Table.FProductQty]" Format="Number" Format.UseLocale="true" HorzAlign="Right" VertAlign="Center" WordWrap="false" Font="???®????¤?????, 9pt" Trimming="EllipsisCharacter"/>
<TextObject Name="Text18" Width="47.25" Height="28.35" Border.Lines="All" Text="[Row#]" VertAlign="Center" Font="???®????¤?????, 9pt"/>
</DataBand>
<PageFooterBand Name="PageFooter1" Top="148.55" Width="718.2" Height="28.35">
<TextObject Name="Text15" Left="233.7" Width="56.7" Height="28.35" Text="Of [TotalPages#]" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 12pt"/>
<TextObject Name="Text16" Left="189" Width="56.7" Height="28.35" Text="[PageN]" HorzAlign="Center" VertAlign="Center" Font="???®????¤?????, 12pt"/>
</PageFooterBand>
</ReportPage>
</Report>


when i run this program, system throw error Table is not connected to the data. Register the data using Report.RegisterData method.

Who can give me a hand. or give me a simple in asp.net web form.

Comments

  • edited 10:57AM
    Hello,

    Change the following line:
    wrptPuchasePrint.Report.RegisterData(dtPushasePrint, "Table");
    with this one:
    wrptPuchasePrint.Report.RegisterData(dtPushasePrint.Tables[0], "Table");
  • edited 10:57AM
    yes.

    and i want to know :

    DataBand band = FReport.FindObject("Data1") as DataBand;
    band.DataSource = FReport.GetDataSource("Table");


    What is the use ?

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.