English 中文(简体)
Wp7 数据联接例外
原标题:Wp7 dataconnectivity exception
  • 时间:2012-05-11 11:19:56
  •  标签:
  • c#

i have written a code to map a table emp contain fields empId empName Salary. but it throws an exception invalid application session id at button1 click as it reaches the for loop. need help to rectify it . i want to view the empId of a Empname = ss

private const string 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? I had a similar issue and disabling wp7explorer solved the issue.

详情请查阅:。 http://wp7explorer.codeplex.com/workitem/8259





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签