user1108948
user1108948

Reputation:

Error on WCF file

I have a simple WCF application. In the file IService.cs:

namespace WcfService1
{
   [ServiceContract]
   public interface IService
   {
       [OperationContract]
       List<ActiveSP> GetActiveSP();
   }

  [DataContract]
  public class ActiveSP
  {
     [DataMember]
     public string DESCR { get; set; }
  }
}

In the file Service.svc.cs:

namespace WcfService1
{
   public class Service : IService
   {
      SqlConnection Conn;
      SqlCommand Cmd;
      public Service()
      {
         Conn = new SqlConnection("Data Source=myweb;Initial Catalog=PeopleSoft;Integrated Security=True;");
      }

     public List<ActiveSP> GetActiveSP()
     {
        Conn.Open();
        Cmd = new SqlCommand();
        Cmd.Connection = Conn;
        Cmd.CommandText = "Select DESCR from myTable"; // return column (varchar type) 
        SqlDataReader Reader = Cmd.ExecuteReader();
        List<ActiveSP> 1stSP = new List<ActiveSP>(); // wrong here
        while (Reader.Read())
        {
            // blah
         }
      }
   }
 }

The error please see the image: error

Thanks.

Upvotes: 0

Views: 52

Answers (4)

Joachim Isaksson
Joachim Isaksson

Reputation: 180947

You can't call a variable 1stSP, the first character in a variable name needs to be a letter or an underscore, not a number.

Here is some more information on valid identifiers

Upvotes: 2

Mike
Mike

Reputation: 418

You can't start a variable name with a digit in C# I'm pretty sure.

Upvotes: 0

eburgos
eburgos

Reputation: 2053

rename 1spSP to firstSP or something like that :) Identifiers can't start with numbers.

Upvotes: 0

Phillip Schmidt
Phillip Schmidt

Reputation: 8818

You can't start a variable name with a number. That's what's throwing it off.

Upvotes: 0

Related Questions