在三层DAL,BLL和VIEW LAYER中使用Datareader [英] using Datareader in three tier DAL,BLL and VIEW LAYER

查看:61
本文介绍了在三层DAL,BLL和VIEW LAYER中使用Datareader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在学习C#,我在如何在数据访问层,业务层和视图层的三层开始中使用DATA READER时遇到一些问题,任何人都可以通过示例至少从数据库中选择查询方法来帮助我请问如何使用数据读取器在这三层中进行操作. :(

Hi Guys!

I am learning C# i`m having a bit of problem on how to use DATA READER in three tier start in data access layer followed by business layer and last in view layer can any one help me by example at least select query method from the database how to use the datareader to do it in those three layers please. :(

推荐答案

这是您可能需要在使用数据读取器时使用的代码块

Here is the code block which you might need to use for Using Data reader

Dim myCMD As SqlCommand = New SqlCommand("SELECT CategoryID, CategoryName FROM Categories;" & _
                                         "SELECT EmployeeID, LastName FROM Employees", nwindConn)
nwindConn.Open()
Dim myReader As SqlDataReader = myCMD.ExecuteReader()
Dim fNextResult As Boolean = True
Do Until Not fNextResult
  Console.WriteLine(vbTab & myReader.GetName(0) & vbTab & myReader.GetName(1))
  Do While myReader.Read()
    Console.WriteLine(vbTab & myReader.GetInt32(0) & vbTab & myReader.GetString(1))
  Loop
  fNextResult = myReader.NextResult()
Loop
myReader.Close()
nwindConn.Close()
[C#]
SqlCommand myCMD = new SqlCommand("SELECT CategoryID, CategoryName FROM Categories;" +
                                  "SELECT EmployeeID, LastName FROM Employees", nwindConn);
nwindConn.Open();
SqlDataReader myReader = myCMD.ExecuteReader();
do
{
  Console.WriteLine("\t{0}\t{1}", myReader.GetName(0), myReader.GetName(1));
  while (myReader.Read())
    Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
} while (myReader.NextResult());
myReader.Close();
nwindConn.Close();



关于在多层中使用数据读取器,我建议使用自定义数据实体类(具有get和Set方法)或DataTables/DataSet或其他方式在层之间传输数据.



And regarding using Data Reader in multiple layers, I would rather suggest to use Custom Data Entity Classes (which have get and Set Methods), or DataTables/DataSets or other ways to transfer data between the layers.


这篇关于在三层DAL,BLL和VIEW LAYER中使用Datareader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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