ASP.NET创建类 [英] ASP.NET create class

查看:74
本文介绍了ASP.NET创建类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助创建类文件或任何其他过程来做到这一点:

我想创建一个网站,希望在各个页面中使用相同的选择命令.因此,如何只在一页中写选择命令,而不是在所有页中都重复.

但是有时候我的选择命令需要不同的列.那我该怎么做
在此先感谢

Please help to create class file or any other procedure to do that:

I want to create a website where i want the same select command in various page. so how can i write the select command in only one page not repeat in all pages.

But sometimes my select commands required different columns. so how can i do that
Thanks in advance

推荐答案

一个可能的解决方案是编写一个实用程序类并创建一个查询数据库的静态方法.

One possible solution would be to write a utility class and create a static method which queries your database.

public class DataAccessLayer
      {
          public static DataTable GetData()
          {
              DataTable DBResponce = new DataTable();

              // Do Query and fill table

              return DBResponce;
          }
      }



然后,您可以从另一个类访问此内容:



You can then access this from another class :

DataTable DataSet = DataAccessLayerXmlDAO.GetData();



尽管如果每次都获取相同的数据并且需要传递数据,则在实例化新类时考虑在构造函数中传递数据.

希望这对您有帮助

劳伦斯



Although if you''re getting the same data each time and you need to pass it around, consider passing it in the constructor when instantiating a new class.

Hope this helps

Laurence


这篇关于ASP.NET创建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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