locked
A get or set accessor expected

    Question

  • Hi,
    I've got this problem in the following bold place but I have no problems at all in the 2nd subroutine
    Error 1 A get or set accessor expected 

            private int new_user_id
            {
                conn.ConnectionString = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ibmpc)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User ID=abc;Password=abc;";

                ...
            }

            private void save_rec(string p_edt_stat, int p_user_id)
            {
                conn.ConnectionString = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ibmpc)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User ID=abc;Password=abc;";
                ...

    "conn" is declared as

        public class Form1 : Form
        {
            ...
            OracleConnection conn = new OracleConnection();
            ...

    Monday, December 08, 2008 4:41 AM

Answers

  • The below portion is a declaration for a property of integer type and there is no get & set for the property so thats the error.

     

    private int new_user_id
            {
                conn.ConnectionString = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ibmpc)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User ID=abc;Password=abc;";

                ...
            }

    so you can have it like :

     

    private int _newuserid;

    private int new_user_id
            {

            get{ return _newuserid;}

            set{_newuserid =value;}
            }

     

    whereas the 2nd subroutine in your post is a method where you are setting the connection string so that works fine.
    Monday, December 08, 2008 5:25 AM
  • Looks like you intended to write a method instead of a property.  You forgot the parentheses:

      private int new_user_id()
      {
         // etc...
      }

    Monday, December 08, 2008 1:28 PM

All replies

  • The below portion is a declaration for a property of integer type and there is no get & set for the property so thats the error.

     

    private int new_user_id
            {
                conn.ConnectionString = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ibmpc)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User ID=abc;Password=abc;";

                ...
            }

    so you can have it like :

     

    private int _newuserid;

    private int new_user_id
            {

            get{ return _newuserid;}

            set{_newuserid =value;}
            }

     

    whereas the 2nd subroutine in your post is a method where you are setting the connection string so that works fine.
    Monday, December 08, 2008 5:25 AM
  • Looks like you intended to write a method instead of a property.  You forgot the parentheses:

      private int new_user_id()
      {
         // etc...
      }

    Monday, December 08, 2008 1:28 PM