共享数据库访问, [英] Shared Database access,

查看:106
本文介绍了共享数据库访问,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我有2个问题..

首先,在我的项目中,我想在Windows窗体应用程序和Web应用程序之间创建一个公共数据库。那么,是否可以在visual studio中创建这种共享数据库。???



其次,我想在gridview i中添加手动列,e。该列的数据不是来自数据库,而是我手动计算。具体来说,我想在gridview中添加名为FINE的列,我正在通过编程来计算......所以告诉我是否有任何方法可以将这些数据添加到gridview中以打印我的结果...

,是的,我想在我的网络应用程序中做上面的事情...

Actually i have 2 questions..
Firstly,In my project i want to make one common database between windows form application and web application. So, is this possible to make this kind of shared database in visual studio.???

Secondly, I want to add manual column in gridview i,e. data of that column is not coming from database and i'm calculating it manually. Specifically i want to add Column named "FINE" in gridview which i'm calculating by programming... so tell me if there is any way to add that data into gridview to print my results...
and yeah i want to do above thing in my web application...

推荐答案

数据库不关心,也不了解使用它们的应用程序。数据库没有什么特别之处,只能使它可用于Web应用程序或Windows应用程序。两者都可以同时使用同一个数据库。



计算列可以在数据库本身完成,如果业务规则允许,或者可以在应用程序中完成代码。



如何执行此操作取决于您的业务逻辑以及您如何执行特定操作。最常见的做法是将数据从数据库加载到DataTable对象中,向其中添加新列,然后迭代DataTable中的Rows并计算每行的结果,将值放在新列中。完成后,您可以将网格绑定到DataTable进行显示。
Databases don't care about, nor know anything about, the application that's using them. There is nothing special about a database that make it only usable to a web application or to a Windows application. Both can use the same database at the same time.

Calculated columns can be done in the database itself, if business rules permit, or they can be done in your application code.

How you do this depends on your business logic and how you're doing specific operations. The most general thing to do would be to load your data from the database into a DataTable object, add a new column to it, then iterate over the Rows in the DataTable and calculate your result for each row, putting the value in your new column. Once that's done you can bind your grid to the DataTable for display.


首先,是的,您可以将多个项目,应用程序和网站/应用程序都指向1个中央数据库。



秒有几种方法可以获得计算额外列所需的内容。我很可能会创建一个绑定到gridview的对象(并且每行有一个列表1),其中一个属性是计算列,要么提前计算并将其放入列中,要么该属性可以从对象中的其他值计算值,然后我就这样做。这将有助于从UI中获取更多业务逻辑。 (良好的编程习惯)。
First,yes you can have multiple projects, applications, and web sites/applications all pointing to 1 central database.

second there are several ways to get what you want for calculating the extra column. I would most likely make an object that binds to the gridview (and you'll have a list of them 1 for each row) and one of the properties would be the calculated column, either calculate it early and put it in the column or if the property can calculate the value from the other values in the object then I'd do it that way. This will help take more business logic out of the UI. (good programming practice).


这篇关于共享数据库访问,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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