我遇到了一個問題,即無論用戶何時創建新記錄,程序都必須檢查數據是否已經創建爲非。我的代碼目前有一些錯誤,我無法找到錯誤所在。任何人都可以給我一些意見?謝謝!驗證檢查數據庫中的重複數據
下面是代碼,讓你們有更多的瞭解我的問題。要比較
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();
}
}
任何幫助將不勝感激。
究竟是什麼錯誤? – 2012-08-01 01:45:42
我已經發布了我設法找到的答案以及它的工作。 – rookie 2012-08-01 01:55:56
...它的工作...現在.... :) – Darek 2012-08-01 03:34:17