C# app not running correctly

Posted on 2006-05-01
Last Modified: 2008-02-01
I have added a developed an app in c# with a Crystal report, but Im having problems with it, due to the fact that the database I am logging onto has a username and password. The code is below after the question. I am getting the error messages

The name reportdocument1 does not exist in the class or namespace

Can anybody help



using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace WindowsApplication1
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
private WindowsApplication1.Application_Form
            private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public Form1()
                  // Required for Windows Form Designer support

            // TODO: Add any constructor code after InitializeComponent call

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
                  if( disposing )
                        if (components != null)
                  base.Dispose( disposing );

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));

TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
reportDocument1 = new OpenRecords();

ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName =
System.Configuration.ConfigurationSettings.AppSett ings["Server"];
crConnectionInfo.DatabaseName =
System.Configuration.ConfigurationSettings.AppSett ings["DataBase"] ;
crConnectionInfo.UserID =
System.Configuration.ConfigurationSettings.AppSett ings["User"] ;
crConnectionInfo.Password =
System.Configuration.ConfigurationSettings.AppSett ings["Password"] ;

foreach (CrystalDecisions.CrystalReports.Engine.Table table in
TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
crTableLogonInfo.TableName = table.Name;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTableLogonInfos.Add( crTableLogonInfo);
table.ApplyLogOnInfo( crTableLogonInfo);

CrystalReportViewer1.LogOnInfo = crTableLogonInfos;

this.application_Form = new WindowsApplication1.Application_Form();
                  this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                  // application_Form
                  this.application_Form.FileName = "";
                  // crystalReportViewer1
this.crystalReportViewer1.ActiveViewIndex = -1; this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
                  this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);
                  this.crystalReportViewer1.Name = "crystalReportViewer1";
                  this.crystalReportViewer1.ReportSource = this.application_Form;
                  this.crystalReportViewer1.Size = new System.Drawing.Size(292, 266);
                  this.crystalReportViewer1.TabIndex = 0;
                  // Form1
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(292, 266);
                  this.Name = "Form1";
                  this.Text = "Form1";


            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            static void Main()
                  Application.Run(new Form1());
Question by:polynominal
    LVL 19

    Expert Comment

    reportDocument1 = new OpenRecords();

    You did not initialize reportDocument1. I'm no crystal reports specialist, but I guess you could try

    object reportDocument1 = new OpenRecords();
    LVL 4

    Accepted Solution

    Oh friend,
    Let's have a look at it. The following code snippet.

    TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
    reportDocument1 = new OpenRecords();

    You have declare "TableLogOnInfos crTableLogonInfos", so crTableLogonInfos is an object of TableLogOnInfos.
    After declaration we can use.
    The same to reportDocument1, you have call "reportDocument1 = new OpenRecords();" but never had a declaration for reportDocument1.
    Check it again or it will cause compile time error.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now