对比.Net PetShop和Duwamish来探讨Ado.Net的数据库编程模式
.NET PetShop和Duwamish简单介绍
.NET PetShop宠物网上商店首页
public class BookData : DataSet { public BookData() { // // Create the tables in the dataset // BuildDataTables(); } private void BuildDataTables() { // // Create the Books table // DataTable table = new DataTable(BOOKS_TABLE); DataColumnCollection columns = table.Columns; columns.Add(PKID_FIELD, typeof(System.Int32)); columns.Add(TYPE_ID_FIELD, typeof(System.Int32)); columns.Add(PUBLISHER_ID_FIELD, typeof(System.Int32)); columns.Add(PUBLICATION_YEAR_FIELD, typeof(System.Int16)); columns.Add(ISBN_FIELD, typeof(System.String)); columns.Add(IMAGE_FILE_SPEC_FIELD, typeof(System.String)); columns.Add(TITLE_FIELD, typeof(System.String)); columns.Add(DESCRIPTION_FIELD, typeof(System.String)); columns.Add(UNIT_PRICE_FIELD, typeof(System.Decimal)); columns.Add(UNIT_COST_FIELD, typeof(System.Decimal)); columns.Add(ITEM_TYPE_FIELD, typeof(System.String)); columns.Add(PUBLISHER_NAME_FIELD, typeof(System.String)); this.Tables.Add(table); } ……… }
private SqlDataAdapter dsCommand; public BookData GetBookById(int bookId) { return FillBookData("GetBookById", "@BookId", bookId.ToString()); } private BookData FillBookData(String commandText, String paramName, String paramValue) { if (dsCommand == null ) { throw new System.ObjectDisposedException( GetType().FullName ); } BookData data = new BookData(); SqlCommand command = dsCommand.SelectCommand; command.CommandText = commandText; command.CommandType = CommandType.StoredProcedure; // use stored proc for perf SqlParameter param = new SqlParameter(paramName, SqlDbType.NVarChar, 255); param.Value = paramValue; command.Parameters.Add(param); dsCommand.Fill(data); return data; }
public CustomerData GetCustomerByEmail(String emailAddress, String password) { // // Check preconditions // ApplicationAssert.CheckCondition(emailAddress != String.Empty, "Email address is required", ApplicationAssert.LineNumber); ApplicationAssert.CheckCondition(password != String.Empty, "Password is required", ApplicationAssert.LineNumber); // // Get the customer dataSet // CustomerData dataSet; using (DataAccess.Customers customersDataAccess = new DataAccess.Customers()) { dataSet = customersDataAccess.LoadCustomerByEmail(emailAddress); } // // Verify the customer's password // DataRowCollection rows = dataSet.Tables[CustomerData.CUSTOMERS_TABLE].Rows; if ( ( rows.Count == 1 ) && rows[0][CustomerData.PASSWORD_FIELD].Equals(password) ) { return dataSet; } else { return null; } }
dataSet = customersDataAccess.LoadCustomerByEmail(emailAddress);
public void RunProc(string procName, out SqlDataReader dataReader) { SqlCommand cmd = CreateCommand(procName, null); dataReader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); }
public ProductResults[] GetList(string catid, int currentPage, int pageSize, ref int numResults) { numResults = 0; int index=0; SqlDataReader reader = GetList(catid); ProductResults[] results = new ProductResults[pageSize]; // now loop through the list and pull out items of the specified page int start = (int)((currentPage - 1) * pageSize); if (start <= 0) start = 1; // skip for (int i = 0; i < start - 1; i++) { if (reader.Read()) numResults++; } if (start > 1) reader.Read(); // read the data we are interested in while (reader.Read()) { if (index < pageSize) { results[index] = new ProductResults(); results[index].productid = reader.GetString(0); results[index].name = reader.GetString(1); index++; } numResults++; } reader.Close(); // see if need to redim array if (index == pageSize) return results; else { // not a full page, redim array ProductResults[] results2 = new ProductResults[index]; Array.Copy(results, results2, index); return results2; } }
public class ProductResults { private string m_productid; private string m_name; // product props public string productid { get { return m_productid; } set { m_productid = value; } } public string name { get { return m_name; } set { m_name = value; } } }
对比.Net PetShop和Duwamish来探讨Ado.Net的数据库编程模式相关推荐
- 多核时代:并行程序设计探讨(7)——并行编程模式概览
并行编程模式概览 前面的5.6篇博文,都是和并行编程相关的基础知识,如果你一路看来,基本上也能够开始进行并行编程设计了,也可以和别人吹吹牛.聊聊天了. 但"欲穷千里目,更上一层楼" ...
- 浅析ado.net获取数据库元数据信息
写这个文章源于早先对ADO.Net获取数据库元数据上的认识,去年我在阅读ADO.Net Core Reference的时候曾经注意过DataSet的FillSchema的这个方法.这方面,在我之前的随 ...
- MFC,ADO方式实现数据库操作
参考: MSDN数据访问编程 (MFC/ATL): https://msdn.microsoft.com/zh-cn/library/kd4ck1tt.aspx?f=255&MSPPError ...
- 详解ADO.NET操作数据库合力创享
详解ADO.NET操作数据库 第一步:http://dl.dbank.com/c0h28bwpss 第二步:http://dl.dbank.com/c0xkrkgp9i 第三步:http://dl.d ...
- ADO.NET的数据库查询2009-12-07 02:20 P.M.ADO.NET的数据库查询
ADO.NET的数据库查询 2009-12-07 02:20 P.M. ADO.NET的数据库查询 一.SqlCommand对象 1:创建SqlCommand对象 l 使用New关键字 ...
- python能和wincc一起用_python通过ado连接wincc数据库
python通过ado连接wincc数据库 注意点: 1,python需要安装32位,64位测试没通过,具体原因不明 2,若使用Provider=WinCCOLEDBProvider.1需要安装WIN ...
- ADO连接各种数据库
通过ADO连接各种数据库的字符串集 海南省信息服务中心 温大文 在网络编程过程中,ADO(Activex Data Object)编程往往是不可少的工作,特别是开发电子商务网站.既然讲到ADO数据对 ...
- 在Visual C++中用ADO进行数据库编程(上)
在Visual C++中用ADO进行数据库编程(上) 1. 生成应用程序框架并初始化OLE/COM库环境 创建一个标准的MFC AppWizard(exe)应用程序,然后在使用ADO数 ...
- 在Visual C++中用ADO进行数据库编程(中)
在Visual C++中用ADO进行数据库编程(中) 4.执行SQL命令并取得结果记录集 为了取得结果记录集,我们定义一个指向Recordset对象的指针:_RecordsetPtr ...
最新文章
- 【学习笔记】ABAP OOD设计模式 - 桥接模式
- PHP各种数据类型转换
- PAT (Basic Level) 1058 选择题(模拟)
- gitchat 会员值得买么_小米雷军亲自站台,599元的星特朗天文望远镜值得买么?...
- [原创]传递UIScrollView的滑动事件到其子视图中
- Winform文件下载之WebClient
- 学习笔记之ulimit
- php获取localstorage的值,localStorage的设置和取值Demo
- 大学学计算机用游戏本好吗,大学学建筑学用什么配置的笔记本电脑好?
- 【BZOJ1475】方格取数 [最小割]
- 小程序navigator点击有时候会闪一下
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)...
- PHP html 转换成PDF wkhtmltopdf HTML 转换成 PDF (JAVA C#都适用)
- 【ITS模型】基于MATLAB的ITS宽带短波信道模型的建模和仿真
- 【ASE学习】-测量石墨烯结构的碳碳键平均键长
- mzy,struts学习(二):struts.xml的配置
- R语言中的igraph包绘制网络图
- 夏天推荐凉快的地方不嫌多!四明山这里更是集凉爽与好玩一起
- jsch jar包连接不上ssh报Algorithm negotiation fail 错误
- 营销革命4.0 从传统到数字
热门文章
- 使用Python,OpenCV查找图像中的最亮点
- 1数字图像获取:1.2图像灰度直方图
- keras 的 example 文件 mnist_swwae.py 解析
- 【TensorFlow2.0】(7) 张量排序、填充、复制、限幅、坐标选择
- linux笔记软件,Linux Ubuntu学习笔记_软件管理
- python for i in range 三维_python中的三维卷积
- Open3d学习计划—高级篇 8(网格变形)
- 【小妙招】【旧版】欢庆网自动搜索请柬console方法
- shell设置系统环境变量的问题
- ATS 5.3.0日志字段分析(续)