'A namespace does not directly contain members such as fields or methods'

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

    'A namespace does not directly contain members such as fields or methods'

    Hi

    I new to C# progrmming. I have taken a sample code from the internet and
    try to compile it. I am getting the error

    'A namespace does not directly contain members such as fields or methods'

    and the code is

    ----------------------
    using System;
    using System.Data;
    using System.Data.ADO ;

    Namespace DBAccess
    {


    public class DBRead
    {
    public ADODataReader DataReader(stri ng DBStr,string strSQL)
    {
    // Create the connection
    ADOConnection oCn = new ADOConnection(D BStr);
    //Create the Command Object
    ADOCommand oCm = new ADOCommand(strS QL,oCn);
    //Open the connection
    oCn.Open();
    //Create a null DataReader Object
    ADODataReader oDr ;
    //Execute the SQL Query
    oCm.Execute(out oDr);
    // Return the DataReader
    return oDr;
    }
    }
    }
    ----------------------

    Any idea what is wrong with this code.

    TIA

    RAO



  • 100

    #2
    Re: 'A namespace does not directly contain members such as fields or methods'

    Hi RAO,

    C# is case sensitive, so the error is that you wrote *Namepsace* with
    capital *N*. Write *namespace* instead.

    HTH
    B\rgds
    100
    "RAO" <narayanarao@ho tmail.com> wrote in message
    news:O4%23zvH4g DHA.1008@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Hi
    >
    > I new to C# progrmming. I have taken a sample code from the internet and
    > try to compile it. I am getting the error
    >
    > 'A namespace does not directly contain members such as fields or methods'
    >
    > and the code is
    >
    > ----------------------
    > using System;
    > using System.Data;
    > using System.Data.ADO ;
    >
    > Namespace DBAccess
    > {
    >
    >
    > public class DBRead
    > {
    > public ADODataReader DataReader(stri ng DBStr,string strSQL)
    > {
    > // Create the connection
    > ADOConnection oCn = new ADOConnection(D BStr);
    > //Create the Command Object
    > ADOCommand oCm = new ADOCommand(strS QL,oCn);
    > //Open the connection
    > oCn.Open();
    > //Create a null DataReader Object
    > ADODataReader oDr ;
    > //Execute the SQL Query
    > oCm.Execute(out oDr);
    > // Return the DataReader
    > return oDr;
    > }
    > }
    > }
    > ----------------------
    >
    > Any idea what is wrong with this code.
    >
    > TIA
    >
    > RAO
    >
    >
    >[/color]


    Comment

    • Jon Skeet

      #3
      Re: 'A namespace does not directly contain members such as fields or methods'

      RAO <narayanarao@ho tmail.com> wrote:[color=blue]
      > I new to C# progrmming.[/color]

      In that case, I *strongly* suggest you start with the basics, rather
      than diving straight into database access.
      [color=blue]
      > I have taken a sample code from the internet and
      > try to compile it. I am getting the error
      >
      > 'A namespace does not directly contain members such as fields or methods'[/color]

      C# is case sensitive. Your line:
      [color=blue]
      > Namespace DBAccess[/color]

      should be

      namespace DBAccess

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      Working...