Wp7 dataconnectivity异常

时间:2012-05-11 11:19:56

标签: c#

我已经编写了一个代码来映射表emp包含字段empId empName Salary。 但是当它到达for循环时,它会在button1单击时抛出异常无效的应用程序会话ID。需要帮助来纠正它。我想查看Empname = ss的empId

私有const字符串ConnectionString =“isostore:/Emp1.sdf”;

    [Table(Name = "Emp")]
    public class Emp2
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = true)]
        public int EmpId
        {
            get;
            set;
        }
        [Column]
        public string EmpName
        {
            get;
            set;
        }
        [Column]
        public int Salary
        {
            get;
            set;
        }
    }


    public MainPage()
    {
        InitializeComponent();

        using (CountryDataContext context = new CountryDataContext(ConnectionString))
        {

            if (!context.DatabaseExists())
            {

                context.CreateDatabase();

            }
            else
            {
                MessageBox.Show("Employee table exist already");
            }
        }




    }


    private IList<Emp2> getcountry()
    {
        IList<Emp2> countryList = null;
        using (CountryDataContext context = new CountryDataContext(ConnectionString))
        {
            IQueryable<Emp2> query = from c in context.Emp where c.EmpName=="ss"   select c;
            countryList = query.ToList();
        }

        return countryList;
    }



    public class CountryDataContext : DataContext
    {
        public CountryDataContext(string connectionString)
            : base(connectionString)
        {

        }
        public Table<Emp2> Emp
        {
            get
            {
                return this.GetTable<Emp2>();
            }
        }


    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        IList<Emp2> emp= this.getcountry();

        try
        {
            foreach (Emp2 a in emp)
            {
                MessageBox.Show(a.EmpId.ToString());

            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }


    }

1 个答案:

答案 0 :(得分:0)

你是否正在使用wp7explorer? 我有一个类似的问题,禁用wp7explorer解决了这个问题。

有关详细信息,请查看以下链接:http://wp7explorer.codeplex.com/workitem/8259