note

来源:互联网 发布:淘宝里最贵的东西 编辑:程序博客网 时间:2024/05/16 02:54
  p protected void Button1_Click(object sender, EventArgs e)
        {
            ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", GetTable()));
            ReportViewer1.DataBind();
        }
        public DataTable GetTable()
        {
            string sym1 = Convert.ToString("JNI120O9");
            string sym2 = Convert.ToString("JNI120C9");
            BLL.BLL bll = new BLL.BLL();
            return bll.GetDataTable(sym1, sym2);
        }


 public class BLL
    {
        public DataTable GetDataTable(string sym1, string sym2)
        {
            DAL.DBHelper helper = new DAL.DBHelper();          
            SqlParameter pl = new SqlParameter("@sym1", sym1);
            SqlParameter p2 = new SqlParameter("@sym2", sym2);
            
            SqlParameter[] paras=new SqlParameter[] { pl, p2 };
            return helper.ExecuteSqlReturnDt("select top 10 * from VOL_prices p, VOL_options o where p.id=o.id and  sym=@sym1 or sym=@sym2", paras);
          
        }
    }


 public class DBHelper
    {
        SqlConnection conn;
        public DBHelper()
        {
            conn = new SqlConnection("");
        }
        public DataTable ExecuteSqlReturnDt(string sql, SqlParameter[] paras)      
        {
            SqlCommand cmd = new SqlCommand(sql);          
            cmd.Connection = conn;
          
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.SelectCommand.Parameters.AddRange(paras);
            DataSet ds = new DataSet();
            da.Fill(ds);//Open conn,execute,close conn
            return ds.Tables[0];
        }
    }

0 0
原创粉丝点击