在C#中更新两个Joned SQL表中的一个 [英] Update one of two joned SQL tables in C#

查看:83
本文介绍了在C#中更新两个Joned SQL表中的一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习C#和SQL数据库。我认为尝试开发一个非常简单的程序会有助于此。但是,我在这一点上摇摆不定。



以下Select命令工作正常:

I am trying to learn C# and SQL Databases. I thought that trying to develop a very simple program would assist in this. However, I am wavering on that point.

The following Select command works fine:

findCommand = new SqlCommand("Select   Bought.Stockid, 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);

然后我使用CurrencyManager编辑,添加和删除行。然后在关闭应用程序时,我想要更新所有记录,包括对任何记录进行的任何添加,删除或更改。我认为以下代码会这样做。但是,应用程序关闭没有任何问题,但我所做的所有更改都将丢失。

I have then used the CurrencyManager to edit, add and delete rows. Then on closing the application I want to update all records with any additions, deletions or changes that have been made to any of the records. I thought that the following code would do it. However, the application closes without any problem but all changes I have made are lost.

findCommand = new SqlCommand("UPDATE Bought SET Bought.Stockid = Bought.Stockid, Bought.BuyDate = Bought.BuyDate , Bought.Number_Bought = Bought.Number_Bought," +
                         " Bought.Price = Bought.Price, Bought.Brokerage = Bought.Brokerag, Bought.Number_Bought = Bought.Number_Bought,  Bought.Interest_Rate = Bought.Interest_Rate, Bought.Acc_Interest = Bought.Acc_Interest, " +
                          "Bought.Total_Cost = Bought.Total_Cost, Bought.BuyNotes =Bought.BuyNotes " +
                         " FROM Bought  INNER JOIN ASXCode ON Bought.Stockid = ASXCode.Stockid", JKPLConnection);



我对发布这个问题感到担心,因为我不知道我是否提供了足够的信息或是否全部问题可能被认为是愚蠢的。但是,我已经用完了其他选项。


I am apprehensive about posting this question because I don't know whether I have provided sufficient information or whether the whole question might be considered dumb. However, I have run out of other options.

推荐答案

嗯...看看你的更新命令。

我会削减它到了基础,所以你可以更清楚地看到它在做什么:

Well...look at your update command.
I'll pare it down to the basics so you can see more clearly what it is doing:
UPDATE Bought SET Stockid = Stockid, BuyDate = BuyDate , ...



这意味着将字段的值设置为当前价值。

实际上,它实际上是在扔掉一个特殊的,而不是执行,因为你忘了经纪中的最后一个e:


Which means "Set the value of the field to it's current value".
The chances are that it's actually throwing an exceptiopn rather than executing at all, since you forgot the final "e" in "Brokerage":

.Price, Bought.Brokerage = Bought.Brokerag, Bought.

因此,除非有两个名称非常相似的列,否则SQL不会高兴。



我无法建议您需要做什么 - 我不知道您要在CurrencyManager中存储要保存的信息的位置(我假设这个是你的应用程序的名称?) - 但你需要更仔细地思考你想要做什么:甚至修复,SQL不会做任何有用的事情。

So unless there are two columns with very similar names SQL is not going to be happy.

I can't suggest what you need to do - I don't know where you are storing the info you want to save in "CurrencyManager" (I assume this is the name of your app?) - but you do need to think a little more carefully about what you are trying to do: even fixed, that SQL isn't going to do anything useful.


这篇关于在C#中更新两个Joned SQL表中的一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆