ADO Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Bailey

    ADO Error

    When I execute the following code on a WebForm I get the
    following message:

    Object reference not set to an instance of an object.

    This error occurs at the dataConnection. ConnectionStrin g
    command.

    public void OpenWorkorder()
    {
    string connStr
    = "Provider=MSDAO RA.1;User ID=maximo;Data
    Source=Demo;Pas sword=xxxxxx";
    dataConnection. ConnectionStrin g =
    connStr;
    dataConnection. Open();

    string strSelect = "Select Wonum
    from Workorder where Wonum =" + workorderText.T ext;
    dataCommand.Con nection =
    dataConnection;
    dataCommand.Com mandText =
    strSelect;
    dataCommand.Exe cuteReader();

    while (dataReader.Rea d())
    {
    string Wonum =
    dataReader.GetS tring(1);
    wonumLabel.Text = Wonum;
    }
    dataReader.Clos e();
    dataConnection. Close();

    If anyone could help, Please

    Dave
  • Carlson Quick

    #2
    Re: ADO Error


    "Dave Bailey" <anonymous@disc ussions.microso ft.com> wrote in message
    news:02f001c39e 48$b91ff8a0$a10 1280a@phx.gbl.. .[color=blue]
    > When I execute the following code on a WebForm I get the
    > following message:
    >
    > Object reference not set to an instance of an object.
    >
    > This error occurs at the dataConnection. ConnectionStrin g
    > command.
    >
    > public void OpenWorkorder()
    > {
    > string connStr
    > = "Provider=MSDAO RA.1;User ID=maximo;Data
    > Source=Demo;Pas sword=xxxxxx";
    > dataConnection. ConnectionStrin g =
    > connStr;
    > dataConnection. Open();
    >
    > string strSelect = "Select Wonum
    > from Workorder where Wonum =" + workorderText.T ext;
    > dataCommand.Con nection =
    > dataConnection;
    > dataCommand.Com mandText =
    > strSelect;
    > dataCommand.Exe cuteReader();[/color]

    You are never initializing the data reader, you nead something more like
    this here
    SqlDataReader dataReader = dataCommand.Exe cuteReader();
    [color=blue]
    >
    > while (dataReader.Rea d())
    > {
    > string Wonum =
    > dataReader.GetS tring(1);
    > wonumLabel.Text = Wonum;
    > }
    > dataReader.Clos e();
    > dataConnection. Close();
    >
    > If anyone could help, Please
    >
    > Dave[/color]


    Comment

    • Ryan Lee

      #3
      ADO Error

      Dave,

      You have to initialize the dataConnection object. If it
      is a OleDbConnection object using the System.Data.Ole Db
      namespace you would reference it this way in C#:

      OleDbConnection dataConnection = new OleDbConnection ();

      Then do all the rest of it. Remember C# is object
      oriented so almost every object has to be initialized.

      Regards,

      Ryan
      [color=blue]
      >-----Original Message-----
      >When I execute the following code on a WebForm I get the
      >following message:
      >
      >Object reference not set to an instance of an object.
      >
      >This error occurs at the dataConnection. ConnectionStrin g
      >command.
      >
      >public void OpenWorkorder()
      > {
      > string connStr
      >= "Provider=MSDAO RA.1;User ID=maximo;Data
      >Source=Demo;Pa ssword=xxxxxx";
      > dataConnection. ConnectionStrin g =
      >connStr;
      > dataConnection. Open();
      >
      > string strSelect = "Select Wonum
      >from Workorder where Wonum =" + workorderText.T ext;
      > dataCommand.Con nection =
      >dataConnection ;
      > dataCommand.Com mandText =
      >strSelect;
      > dataCommand.Exe cuteReader();
      >
      > while (dataReader.Rea d())
      > {
      > string Wonum =
      >dataReader.Get String(1);
      > wonumLabel.Text = Wonum;
      > }
      > dataReader.Clos e();
      > dataConnection. Close();
      >
      >If anyone could help, Please
      >
      >Dave
      >.
      >[/color]

      Comment

      • Guest's Avatar

        #4
        ADO Error

        This works just as it should

        Many Thanks,

        Dave[color=blue]
        >-----Original Message-----
        >Dave,
        >
        >You have to initialize the dataConnection object. If it
        >is a OleDbConnection object using the System.Data.Ole Db
        >namespace you would reference it this way in C#:
        >
        >OleDbConnectio n dataConnection = new OleDbConnection ();
        >
        >Then do all the rest of it. Remember C# is object
        >oriented so almost every object has to be initialized.
        >
        >Regards,
        >
        >Ryan
        >[color=green]
        >>-----Original Message-----
        >>When I execute the following code on a WebForm I get the
        >>following message:
        >>
        >>Object reference not set to an instance of an object.
        >>
        >>This error occurs at the dataConnection. ConnectionStrin g
        >>command.
        >>
        >>public void OpenWorkorder()
        >> {
        >> string connStr
        >>= "Provider=MSDAO RA.1;User ID=maximo;Data
        >>Source=Demo;P assword=xxxxxx" ;
        >> dataConnection. ConnectionStrin g =
        >>connStr;
        >> dataConnection. Open();
        >>
        >> string strSelect = "Select Wonum
        >>from Workorder where Wonum =" + workorderText.T ext;
        >> dataCommand.Con nection =
        >>dataConnectio n;
        >> dataCommand.Com mandText =
        >>strSelect;
        >> dataCommand.Exe cuteReader();
        >>
        >> while (dataReader.Rea d())
        >> {
        >> string Wonum =
        >>dataReader.Ge tString(1);
        >> wonumLabel.Text = Wonum;
        >> }
        >> dataReader.Clos e();
        >> dataConnection. Close();
        >>
        >>If anyone could help, Please
        >>
        >>Dave
        >>.
        >>[/color]
        >.
        >[/color]

        Comment

        Working...