简体   繁体   English

WP7数据连接异常

[英]Wp7 dataconnectivity exception

i have written a code to map a table emp contain fields empId empName Salary. 我已经写了一个代码来映射表emp包含字段empId empName Salary。 but it throws an exception invalid application session id at button1 click as it reaches the for loop. 但在到达for循环时,在button1单击时会引发异常无效的应用程序会话ID。 need help to rectify it . 需要帮助纠正它。 i want to view the empId of a Empname = ss 我想查看Empname = ss的empId

private const string ConnectionString = "isostore:/Emp1.sdf"; 私有常量字符串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);
        }


    }

Could it be that you are using wp7explorer? 可能是您正在使用wp7explorer吗? I had a similar issue and disabling wp7explorer solved the issue. 我有一个类似的问题,禁用wp7explorer解决了该问题。

For more information, check out this link: http://wp7explorer.codeplex.com/workitem/8259 有关更多信息,请查看此链接: http : //wp7explorer.codeplex.com/workitem/8259

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM