在page_load()裡面呼叫report()
ui
只拉元件就好了
用SqlDataSource1捉使用者selectquery的dataset 給crystalreport
在到.rpt設定
protected void report()
{
SqlDataSource1.ConnectionString = WebConfigurationManager.ConnectionStrings["TestReportConnectionString"].ConnectionString;
DataTable dt = new DataTable();
String openwin = "";
String sql = TextBox1.Text.Trim();
if (String.IsNullOrEmpty(sql))
{
SqlDataSource1.SelectCommand = "select * from company";
dt = ((DataView)this.SqlDataSource1.Select(DataSourceSelectArguments.Empty)).ToTable();
}
else
{
SqlDataSource1.SelectCommand = "select * from company where companyId=" + "'" + TextBox1.Text + "'";
dt = ((DataView)this.SqlDataSource1.Select(DataSourceSelectArguments.Empty)).ToTable();
}
Response.Cache.SetCacheability(HttpCacheability.NoCache); //clear cache
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("CrystalReport.rpt"));
rd.SetDataSource(dt);
CrystalReportViewer1.ReportSource = rd;
GridView1.DataSourceID = SqlDataSource1.ID;
}
2010年3月14日 星期日
2010年3月4日 星期四
下拉式選單+連結資料庫 c# 版
SqlConnection Conn1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["TestReportConnectionString"].ConnectionString);
SqlDataAdapter da1 = new SqlDataAdapter("select version from product where productName='萬能廚師系列'", Conn1);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "product");
DropDownList3.AutoPostBack = true;
DropDownList3.DataTextField = "version";
DropDownList3.DataValueField = "version";
DropDownList3.DataSource = ds1.Tables["product"].DefaultView;
DropDownList3.DataBind();
Conn1.Close();
SqlDataAdapter da1 = new SqlDataAdapter("select version from product where productName='萬能廚師系列'", Conn1);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "product");
DropDownList3.AutoPostBack = true;
DropDownList3.DataTextField = "version";
DropDownList3.DataValueField = "version";
DropDownList3.DataSource = ds1.Tables["product"].DefaultView;
DropDownList3.DataBind();
Conn1.Close();
2010年3月3日 星期三
訂閱:
文章 (Atom)