我加入两个表中的一个(买和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