0
我現在堅持關於數組比較並創建它。我有2個桌子,站和位置。站內的列是id和站名。對位置表不一樣的是名稱不同。我把id放入數組中,並將數組的名稱。我想比較名稱和ID,以便當用戶選擇名稱時,程序知道哪個ID屬於所選名稱並使用其主鍵保存到另一個表中。這裏是我從現在開始創建的代碼,但我不知道如何解決它。希望我能在這裏得到一些幫助。謝謝!比較數組並將數據創建到數據庫中
private void btnCreate_Click(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
string[] stations = StationNameList();
int[] stationsID = StationIDList();
string[] locations = LocationNameList();
int[] locationsID = LocationIDList();
int Stationindex = cbStation.SelectedIndex;
int Locationindex = cbLocation.SelectedIndex;
trolleyservice TS = new trolleyservice();
TS.stationID = cbStation.SelectedIndex;
TS.locationID = cbLocation.SelectedIndex;
TS.tServiceTiming = txtTime.Text;
TS.tServiceType = txtType.Text;
Setupctx.trolleyservices.AddObject(TS);
txtTime.Text = "";
txtType.Text = "";
MessageBox.Show("New Trolley Service Has Been Created.");
}
}
這裏是我爲每個表格創建的所有數組。
private string[] StationNameList()
{
using (testEntities Setupctx = new testEntities())
{
return Setupctx.stations.Select(s => s.Station1).OrderBy(s => s).ToArray();
}
}
private int[] StationIDList()
{
using (testEntities Setupctx = new testEntities())
{
return Setupctx.stations.Select(sid => sid.idstations).OrderBy(sid => sid).ToArray();
}
}
private string[] LocationNameList()
{
using (testEntities Setupctx = new testEntities())
{
return Setupctx.locations.Select(l => l.Location1).OrderBy(l => l).ToArray();
}
}
private int[] LocationIDList()
{
using (testEntities Setupctx = new testEntities())
{
return Setupctx.locations.Select(lid => lid.idlocation).OrderBy(lid => lid).ToArray();
}
}
究竟是什麼問題? – 2012-07-30 01:51:39
當我選擇電臺名稱時,我需要電臺名稱來知道它的ID並保存到另一個表中,因爲我使用該ID作爲該表的外鍵。 – rookie 2012-07-30 03:34:01