RPG 与 C# 和 SQL 的比较
在 RPG 程序(AS/400 上的 IBM 语言之一)中,我可以“链接”到一个文件以查看文件中是否存在记录(例如,某个客户记录)。如果是这样,那么我可以立即用新数据更新该记录。如果记录不存在,我可以写一条新记录。代码看起来像这样:
Customer Chain CustFile 71 ;turn on indicator 71 if not found
if *in71 ;if 71 is "on"
eval CustID = Customer;
eval CustCredit = 10000;
write CustRecord
else ;71 not on, record found.
CustCredit = 10000;
update CustRecord
endif
由于不太熟悉 SQL/C#,我想知道是否有一种方法可以从文件中进行随机检索(这就是 RPG 中“链”的作用)。基本上我想看看是否存在记录。如果是,请使用一些新信息更新记录。如果没有,那么我想写一个新的记录。我确信这是可能的,但不太确定如何去做。任何建议将不胜感激。
In an RPG program (One of IBM's languages on the AS/400) I can "chain" out to a file to see if a record (say, a certain customer record) exists in the file. If it does, then I can update that record instantly with new data. If the record doesn't exist, I can write a new record. The code would look like this:
Customer Chain CustFile 71 ;turn on indicator 71 if not found
if *in71 ;if 71 is "on"
eval CustID = Customer;
eval CustCredit = 10000;
write CustRecord
else ;71 not on, record found.
CustCredit = 10000;
update CustRecord
endif
Not being real familiar with SQL/C#, I'm wondering if there is a way to do a random retrieval from a file (which is what "chain" does in RPG). Basically I want to see if a record exists. If it does, update the record with some new information. If it does not, then I want to write a new record. I'm sure it's possible, but not quite sure how to go about doing it. Any advice would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RPG 具有与系统上的数据库表的内在连接。这使得编写这样简洁的操作变得很容易。
另一方面,C# 要求您实现自己的数据库例程(或使用 LINQ 等框架)。
如果我这样做,我将创建一个负责使用 System.OLEDB 对象进行数据库操作的类。
有些方法可能是(一般想法,而不是实际代码):
然后你的主要方法世界读起来像
RPG has intrinsic connectivity to the database tables on the system. That makes it easy to write such succinct operations.
C#, on the other hand, requires you to implement your own database routines (or use a framework like LINQ).
If I was doing this, I would create a class responsible for database manipulation using the System.OLEDB objects.
Some methods might be (general idea, not actual code):
Then your main method world read something like