简体   繁体   English

SQL-DB连接模块的最佳实践

[英]Best practice for a SQL-DB Connection module

I'm currently trying to improve the sql database module, since we have like 10 different ones that are all slightly different. 我目前正在尝试改善sql数据库模块,因为我们喜欢10种不同的产品,它们都稍有不同。

I'm wondering now what the best practise is to make this sql connection module as usable as possible. 我想知道现在的最佳实践是使此sql连接模块尽可能可用。 Mainly the search query: 主要是搜索查询:

Is

public List<ClassForDatatype> getData(String SQLStatement)

better than 优于

public DataTable getData(String SQLStatement)?

In most places we just want to display the elements we got in a DataGrid. 在大多数地方,我们只想显示在DataGrid中获得的元素。 However we also want to use ToString to create an email. 但是,我们也想使用ToString创建电子邮件。

What are your suggestions here? 您在这里有什么建议?

The first one is the better one. 第一个是更好的。 The reason is that your DB layer should have nothing to do with your view layer. 原因是您的数据库层应该与视图层无关。

EDIT: You could use your second version, because it would be faster (less calls/conversions etc.). 编辑:您可以使用第二个版本,因为它会更快(更少的调用/转换等)。 But if you decide at a certin point that you will switch from a DataGrid to something else, you have to rework a lot of code. 但是,如果您决定在证书点上从DataGrid切换到其他内容,则必须重新编写大量代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM