我的代碼將數據保存到數據庫時遇到問題。我有一個文本框和一個組合框,但是當我在文本框中鍵入數據並在組合框中選擇數據並單擊保存時,沒有任何反應,並且在編譯期間沒有發現錯誤。我能否知道究竟出了什麼問題,並給我一些解決辦法?使用linq將數據保存到數據庫
enter code here private void btnCreate_Click(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
string selectST = cbSeats.SelectedItem.ToString();
string inputST = txtStation.Text;
var createStation = (from createST in Setupctx.stations
where createST.Seats == selectST
where createST.Station1 == inputST
select createST).SingleOrDefault();
if (createStation != null)
{
Setupctx.stations.AddObject(createStation);
Setupctx.SaveChanges();
txtStation.Text = "";
MessageBox.Show("New Station Has Been Created.");
}
}
}
您的幫助將不勝感激。
您試圖更新「createStation」或創建一個新工作站嗎? – 2012-07-13 03:35:19