C# WCF文件出错
我有一个简单的WCF应用程序。在IService.cs文件中:C# WCF文件出错,c#,wcf,C#,Wcf,我有一个简单的WCF应用程序。在IService.cs文件中: namespace WcfService1 { [ServiceContract] public interface IService { [OperationContract] List<ActiveSP> GetActiveSP(); } [DataContract] public class ActiveSP { [DataMember]
namespace WcfService1
{
[ServiceContract]
public interface IService
{
[OperationContract]
List<ActiveSP> GetActiveSP();
}
[DataContract]
public class ActiveSP
{
[DataMember]
public string DESCR { get; set; }
}
}
在文件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
}
}
}
}
错误请参见图片:
谢谢。您不能调用变量1stSP,变量名称中的第一个字符必须是字母或下划线,而不是数字
变量名不能以数字开头。这就是为什么要放弃它。将1SPP重命名为firstSP或类似的名称:
标识符不能以数字开头。我敢肯定,变量名不能以数字C开头。对不起,我应该小心介于l和1之间。