본문 바로가기

C#(ASP.NET)

크리스탈리포트 DB 연결 및 파라미터 셋팅 샘플코드



    protected void Page_Load(object sender, EventArgs e)
    {
        //TableLogOnInfo객체생성
        CrystalDecisions.Shared.TableLogOnInfo cryLogonInfo = new CrystalDecisions.Shared.TableLogOnInfo();

        //계정정보설정
        cryLogonInfo.ConnectionInfo.ServerName = "localhost";
        cryLogonInfo.ConnectionInfo.UserID = "sa";
        cryLogonInfo.ConnectionInfo.Password = "123";
        cryLogonInfo.ConnectionInfo.DatabaseName = "pubs";

        //계정추가
        CrystalReportViewer1.LogOnInfo.Add(cryLogonInfo);
        //로그인창 false 설정
        CrystalReportViewer1.EnableDatabaseLogonPrompt = false;

        //피라메터 설정
        CrystalReportSource1.Report.Parameters.Clear();
        CrystalDecisions.Web.Parameter param = new CrystalDecisions.Web.Parameter();
        param.Name = "city";
        param.DefaultValue = "Oakland"; 
        //파라메터 추가
        CrystalReportSource1.Report.Parameters.Add(param);
    }

[출처] HOONS 닷넷, HOONS 닷넷