我加入兩個表中的一個(買和ASXCode)一起在下面的SELECT語句:C#SQL更新兩個連接表
findCommand = new SqlCommand("Select Bought.Stockid, Bought.Buyid, Bought.BuyDate, Bought.Number_Bought," +
" Bought.Price, Bought.Brokerage, Bought.Number_Bought, Bought.Interest_Rate, Bought.Acc_Interest, " +
"Bought.Total_Cost, Bought.BuyNotes, ASXCode.Stock_Code" +
" FROM Bought INNER JOIN ASXCode ON Bought.Stockid = ASXCode.Stockid " +
" ORDER BY ASXCode.Stock_Code", JKPLConnection);
然後,我有以下代碼到findTable綁定到不同的文本框:
findAdapter = new SqlDataAdapter();
findAdapter.SelectCommand = findCommand;
findTable = new DataTable();
findAdapter.Fill(findTable);
txtBuyId.DataBindings.Add("Text", findTable, "Buyid");
cboS.DataBindings.Add("Text", findTable, "Stock_Code");
dateTimePicker4.DataBindings.Add("Text", findTable, "BuyDate");
txtDateS.DataBindings.Add("Text", findTable, "BuyDate");
txtNumBuyS.DataBindings.Add("Text", findTable, "Number_Bought");
txtPriceS.DataBindings.Add("Text", findTable, "Price");
txtBrokerageS.DataBindings.Add("Text", findTable, "Brokerage");
txtRateS.DataBindings.Add("Text", findTable, "Interest_Rate");
txtOpInterestS.DataBindings.Add("Text", findTable, "Acc_Interest");
txtTotalCostS.DataBindings.Add("Text", findTable, "Total_Cost");
findManager = (CurrencyManager)this.BindingContext[findTable];
我已經能夠編輯,刪除並添加新的記錄到findTable。
我希望在各種變化已對findTable做的事,是更新與修改數據庫的表買。我不能使用SqlCommandBuilder,因爲「動態SQL生成不支持多個基表」。
從我做了我明白,我需要寫我自己的更新語句來更新表買各種搜索。然而,我對如何撰寫這份聲明感到不知所措。我希望有人能告訴我我該如何做到這一點。
請參閱以下網頁:https://msdn.microsoft.com/en-us/library/ms177523.aspx。只使用Update命令而不使用其他行。 Update命令必須具有唯一指定需要更改的行的where語句。通常你在where語句中使用主索引。 – jdweng
您不需要聯接進行更新。您需要爲每個數據庫表單獨更新,但可以合併爲一個命令。 – jdweng