C# app not running correctly

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

Thanks

Poly

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
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
                  //
                  InitializeComponent();

                  //
            // 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)
                        {
                              components.Dispose();
                        }
                  }
                  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
reportDocument1.Database.Tables)
{
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();
                  this.SuspendLayout();
                  //
                  // 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.Controls.Add(this.crystalReportViewer1);
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.ResumeLayout(false);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }
      }
}
polynominalAsked:
Who is Participating?
 
nguyenvinhtuConnect With a Mentor Commented:
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.
Danny
0
 
MsShadowCommented:
reportDocument1 = new OpenRecords();

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

object reportDocument1 = new OpenRecords();
0
All Courses

From novice to tech pro — start learning today.