이제 배열 비교 및 생성에 대해 고민하고 있습니다. 나는 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();
}
}
정확히 무엇이 문제입니까? –
스테이션 이름을 선택할 때 스테이션 이름이 ID임을 알고 해당 ID를 해당 테이블의 외래 키로 사용할 때 다른 테이블에 저장해야합니다. – rookie