牛腩新闻视频 08讲 重构SQLHelper 将重复的内容 放到 构造函数里面 以及 try catch 和 using 和连接字符串

try catch  finally   演示

image

image

 

using  演示

image 

image

当 sdr关闭的时候,跟着 sdr 的conn 也会跟着关闭

CommandBehavior.CloseConnection   在执行该命令时,如果关闭关联的 DataReader 对象,则关联的 Connection 对象也将关闭

而 sdr 也因为是被 using 包围  也会自动关闭 释放

image

使用 using  比 try catch 要方便的多

 

下面关于调整 数据库的连接字符串

打开 web.config

image

image

然后在  SQLHelper.cs里面  添加引用

using System.Configuration;

虽然我们手写了引用,但是在右侧   DAL 层里面  还是没有 Configuration 这个引用的,需要我们手动添加引用

image   当前是没有   下面我们添加引用

image image

这样 右侧就会出现了

image

然后我们修改  SQLHelper 里面的 数据库连接字符串

image

posted @ 2011-10-06 17:57  asp_net老友记  阅读(314)  评论(0编辑  收藏  举报