用VC轻松实现 ADO.net
本文示例源代码或素材下载 本文编译器使用Visual Studio 2005 数据库使用SQL Server 2005 express .net版本为2.0 一、实现模型 ADO.net对每种数据库都提供了专门的连接字,不过每种的连接方式都差不多,所以这里我只用SQL Server来做。我在连接数据库时使用
本文示例源代码或素材下载
本文编译器使用Visual Studio 2005 数据库使用SQL Server 2005 express .net版本为2.0
一、实现模型
ADO.net对每种数据库都提供了专门的连接字,不过每种的连接方式都差不多,所以这里我只用SQL Server来做。我在连接数据库时使用了以下几个步骤:
1.连接数据源
使用Connection对象来连接,对于具体的数据库可用具体的对象,如SQL Server可用SqlConnection对象,不过要注意版本问题。
2.检索需要的数据
使用DataAdapter对象来检索,对于具体的数据库同样可用具体的对象,将来对数据的修改也用到它。
3.将数据填充到本地
使用DataAdapter对象的Fill方法,可以填充到DataSet对象中去。
4.显示数据
使用DataGridView对象可以轻松显示、修改DataSet中的数据。注意ListBox/ListView不再有Report方式。
5.需要注意的地方
将关系定义到客户端上,可以减少和服务器的通信量及服务器的运算压力,从而提升性能。
保存主键及唯一关系需要设置一下DataAdapter对象的MissingSchemaAction属性,但是外键关系必须手动添加到DataSet对象的Relations属性
DataAdapter对象的Fill()方法会自动调用Connection对象的Open()和Close()。
DataAdapter的UpdateBatchSize属性可以将指定数量的命令捆绑起来发送到服务器(减少了通信次数,降低了通信冗余)从而提高性能,但是太高反而会因网络等原因降低性能,默认值为1(禁用),详见MSDN。
DataSet功能十分强大,例如GetXml()方法将数据以可阅读的XML方式输出,GetXmlSchema()方法则输出关系,非常好用。
对象简介Connection
连接数据库的最底层对象,要对它设置连接字。
1 2 下一页

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

Indentation specifications and examples of Go language Go language is a programming language developed by Google. It is known for its concise and clear syntax, in which indentation specifications play a crucial role in the readability and beauty of the code. effect. This article will introduce the indentation specifications of the Go language and explain in detail through specific code examples. Indentation specifications In the Go language, tabs are used for indentation instead of spaces. Each level of indentation is one tab, usually set to a width of 4 spaces. Such specifications unify the coding style and enable teams to work together to compile

The DECODE function in Oracle is a conditional expression that is often used to return different results based on different conditions in query statements. This article will introduce the syntax, usage and sample code of the DECODE function in detail. 1. DECODE function syntax DECODE(expr,search1,result1[,search2,result2,...,default]) expr: the expression or field to be compared. search1,

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these
