Wp7 数据连接异常
本文关键字:异常 连接 数据 Wp7 | 更新日期: 2023-09-27 18:33:48
我写了一个代码来映射一个表emp包含字段empId empName Salary。但它在到达 for 循环时在单击按钮 1 时引发异常无效的应用程序会话 ID。需要帮助来纠正它.我想查看一个 EmpName = ss 的 empId
私有常量字符串 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);
}
}
可能是您正在使用 wp7explorer?我有一个类似的问题,禁用wp7explorer解决了这个问题。
有关更多信息,请查看此链接:http://wp7explorer.codeplex.com/workitem/8259