提高数据访问类 [英] Improving data access class

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

问题描述

几年前,我们(作为一家公司)面临着让我们的开发者停止写作传统的ASP页面,并切换到.NET的场景(反过来System.Data这对于数据的访问)。

A few years ago we (as a company) faced the scenario of getting our developers to stop writing classic asp pages and switch to .net (and in turn system.data for data access).

作为一个所谓短期措施,我写了下面的类,使那些不使用System.Data这与放大器的转换更容易;所有的新对象:

As a supposedly ‘short term’ measure I wrote the following class to make the switchover easier for those not used to system.data & all its new objects:

http://www.heavencore.co.uk/forum/ viewthread.php?thread_id单= 185

这个类的主要目的是保持用法类似于传统的ASP尽可能&功放;保持使用非常简单(加号添加电子邮件警报错误捕获亚达内容十分重要):

The main purpose of this class was to keep usage as similar to classic asp as possible & keep the usage VERY simple (plus to add email alerts for error catching yada yada yada):

Public db As New SimpleDataAccess
Public RS As New DataTable

ConnectDatabase()
db.Execute_Query(RS, "SELECT * FROM whatever WHERE IntColumn = " & tools.parseint(EmployeeID, 0) & " or TextColumn = '" & db,Escape("bla'blabla") & "' ORDER BY IntColumn")
For Each DB_Row As DataRow In RS.Rows
    response.Write(DB_Row("IntColumn"))
Next
CloseDatabase()

现在,这两个主要的原因,这个类很烂:

Now, the two main reasons why this class sucks:

  • SQL注入的东西(parseInt函数和放大器;报价逃逸)!已经被类外完成 - 容易健忘 - 参数化查询,一定要在这里介绍
  • CloseDatabase()必须在页面的末尾手动调用 - 这是经常忘记和一个连接被打开到服务器 - 即使在页面完成渲染等

原因,这个班是很好的:

Reasons why this class was good:

  • 类的用法很简单,让老传统的ASP code很方便地转换为.NET
  • 电子邮件警报查询及放大器;连接错误是在类本身处理无形
  • 在它的2 +年来的工作完美,没有任何问题

我的问题:

是否有任何其他类/建议在那里,让我来替换这一类,但保留了非常简单的用法或会是什么修改Execute_Query()和Execute_NonQuery()方法来处理参数化查询的最佳方法是什么?

Are there any other classes / suggestions out there that will allow me to either replace this class but retain the VERY simple usage OR what would be the best way to modify the Execute_Query() and Execute_NonQuery() methods to handle parameterised queries?

简单是关键!

PS:哪里是一个很好的地方张贴了code大块用于做题?引擎收录等只保留东西了一个月......

PS: Where is a good place to post large chunks of code for use in SO questions? Pastebin etc only keep stuff for a month...

推荐答案

我想的这个可能会帮助您。一大块的code。这个处理几乎所有你需要的每一件事情。您可以在一个数组中传递参数。也可以使用存储过程和使用。没有什么可担心的连接关闭。

I think this might help you. A large chunk of code. This handles almost every thing you need. You can pass parameters in an array. Also can use with stored procedures as well. Nothing to worry about connection closing.

希望这有助于。

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

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