我遇到了一个问题,每当用户创建新记录时,程序必须检查数据是否已经创建。我的代码目前有一些错误,我找不到错误所在。谁能给我一些意见??谢谢!
下面是代码,让你们对我的问题有更多的了解。
private void btnCreate_Click(object sender, EventArgs e)
{
using (satsEntities Setupctx = new satsEntities())
{
//int[] stations = StationNameList();
//int[] locations = LocationNameList();
locationstation ls = new locationstation();
ls.stationID = Convert.ToInt32(cbStation.SelectedValue);
ls.locationID = Convert.ToInt32(cbLocation.SelectedValue);
var checkLS = from CLS in Setupctx.locationstations
where CLS.stationID == Convert.ToInt32(cbStation.SelectedValue)
where CLS.locationID == Convert.ToInt32(cbLocation.SelectedValue)
select CLS;
if (checkLS = checked)
{
MessageBox.Show("This Location Station Has Been Created. Please enter a new Location Station.");
}
else
{
{
Setupctx.locationstations.AddObject(ls);
Setupctx.SaveChanges();
cbStation.SelectedIndex = -1;
cbLocation.SelectedIndex = -1;
MessageBox.Show("New Location Station Is Created");
}
}
}
}
需要比较的列保存在数组中
private int[] LocationNameList()
{
using (satsEntities Setupctx = new satsEntities())
{
return Setupctx.locationstations.Select(x => x.locationID).OrderBy(x => x).ToArray();
}
}
private int[] StationNameList()
{
using (satsEntities Setupctx = new satsEntities())
{
return Setupctx.locationstations.Select(y => y.stationID).OrderBy(y => y).ToArray();
}
}
任何帮助将不胜感激。