Home Database Mysql Tutorial ADO.NET之9-非连接模式,内存中的数据库DataSet,DataTable---Shin

ADO.NET之9-非连接模式,内存中的数据库DataSet,DataTable---Shin

Jun 07, 2016 pm 03:59 PM
Memory database model connect

DataSet被称作数据集,可以比作内存中的数据库,DataSet为ADO.NET核心,支持ADO.NET断开式,分布式数据方案的核心对象也是实现基于非连接的数据查询核心组件 DataTable常用属性: 属性 说明 Columns 获取属于该表的列的集合 Rows 获取属于该表的行的集合 TableNam

DataSet被称作数据集,可以比作内存中的数据库,DataSet为ADO.NET核心,支持ADO.NET断开式,分布式数据方案的核心对象也是实现基于非连接的数据查询核心组件

DataTable常用属性:

属性 说明
Columns 获取属于该表的列的集合
Rows 获取属于该表的行的集合
TableName 获取或设置DataTable的名称

DataTable方法:

方法 说明
AcceptChanges 提交自上次调用AcceptChanges以来对该表进行的所有更改
Clear 清除DataTable内的所有数据
NewRow 创建与该表具有相同架构的新DataRow
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SQLTest
{
    class Program
    {
        static void Main(string[] args)
        {
            ///连接数据库
            DataSet ds = new DataSet();  //创建数据库DataSet对象
            DataTable dt = new DataTable(); //创建数据库DataTable对象
            ds.Tables.Add(dt); //将数据表对象加入数据集对象集合中
            dt.Columns.Add("name", typeof(string));  //向DataTable中添加列
            dt.Columns.Add("address", typeof(string));//向DataTable中添加列
            DataRow dr = dt.NewRow();   //得到数据表,行对象
            dr[0] = "潘潘";
            dr[1] = "武汉";  //向行对象中添加数据
            dt.Rows.Add(dr);
            dt.Rows.Add(new object[] { "潘潘潘", "北京" }); //向数据行中添加新的对象
            foreach(DataRow v in dt.Rows)
            {
                Console.WriteLine("{0} {1}", v[0], v[1]);
            }
            string connection =
                "server=潘尚\\SQLEXPRESS;database=db_test;Trusted_Connection=true";
            SqlConnection sc = new SqlConnection(connection);
        //    sc.ConnectionString = connection;
            try
            {
                sc.Open();  //打开数据库连接
                Console.WriteLine("已经打开数据库连接!");
//START:5.导出数据库中的记录//////////////////////////////////////////////////////////
              /*  SqlCommand cmd = new SqlCommand("SELECT * FROM db_student", sc);
                SqlDataReader sdr = cmd.ExecuteReader(); //执行查找记录命令
                while(sdr.Read())
                {
                    Console.WriteLine("{0}{1}{2}{3}", sdr[0], sdr[1], sdr[2], sdr[3]);
                }  */
//END:5.导出数据库中的记录////////////////////////////////////////////////////////////
//START:4.查询数据库记录//////////////////////////////////////////////////////////////
              /*  SqlCommand cmd = new SqlCommand("SELECT count(*) FROM db_student", sc);
                int i = (int)cmd.ExecuteScalar();//执行查找记录的命令
                Console.WriteLine("表中共有{0}条数据", i.ToString());  */
//END:4.查询数据库记录////////////////////////////////////////////////////////////////
//START:3.修改数据库数据的代码////////////////////////////////////////////////////////
             /*   SqlCommand cmd = new SqlCommand("UPDATE db_student SET student_grade=99 where student_name=@name", sc);  //创建SqlCommand对象
                cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = "潘";
                int i = cmd.ExecuteNonQuery();
                if (i > 0) Console.WriteLine("修改成功!");   */
//END:3.修改数据库数据的代码/////////////////////////////////////////////////////////
//START:1.删除数据库记录代码段///////////////////////////////////////////////////////
               /* string cmdtext = "DELETE FROM db_student WHERE student_name=@name";
                SqlCommand cmd = new SqlCommand(cmdtext, sc);
                cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = "潘";
                int i = cmd.ExecuteNonQuery();
                if (i > 0) Console.WriteLine("删除记录成功!"); */
//END:1.删除数据库记录代码段/////////////////////////////////////////////////////////
//START:2.添加记录的代码///////////////////////////////////////////////////////////////
             /*   SqlCommand cmd = new SqlCommand();//创建SqlCommand对象
                cmd.CommandType = CommandType.Text; //设置执行文本命令
                cmd.Connection = sc; //设置对象属性
                cmd.CommandText = 
                    "INSERT INTO db_student(student_name,student_age,student_address,student_grade)VALUES(@name,@age,@address,@grade)";
                //添加参数并为参数赋值
                cmd.Parameters.Add("@name", SqlDbType.VarChar, 10).Value = "潘";
                cmd.Parameters.Add("@age", SqlDbType.Int).Value = 19;
                cmd.Parameters.Add("@address", SqlDbType.VarChar).Value = "武汉";
                cmd.Parameters.Add("@grade", SqlDbType.Int).Value = 100;
                int i = cmd.ExecuteNonQuery(); //执行数据库添加记录命令
                if (i > 0) Console.WriteLine("添加记录成功"); */  //控制台输出添加记录 
//END:2.添加记录的代码/////////////////////////////////////////////////////////////////
            }
            catch (Exception ex)
            {
                Console.WriteLine("打开数据库错误:{0}", ex.Message);
            }
            finally
            {
                sc.Close();
                Console.WriteLine("数据库连接已关闭!");
            }      
            System.Console.ReadLine();
        }
    }
}
Copy after login

结果:

\

在未打开数据库连接之前,在内存中处理数据

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Large memory optimization, what should I do if the computer upgrades to 16g/32g memory speed and there is no change? Large memory optimization, what should I do if the computer upgrades to 16g/32g memory speed and there is no change? Jun 18, 2024 pm 06:51 PM

For mechanical hard drives or SATA solid-state drives, you will feel the increase in software running speed. If it is an NVME hard drive, you may not feel it. 1. Import the registry into the desktop and create a new text document, copy and paste the following content, save it as 1.reg, then right-click to merge and restart the computer. WindowsRegistryEditorVersion5.00[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\MemoryManagement]"DisablePagingExecutive"=d

Sources say Samsung Electronics and SK Hynix will commercialize stacked mobile memory after 2026 Sources say Samsung Electronics and SK Hynix will commercialize stacked mobile memory after 2026 Sep 03, 2024 pm 02:15 PM

According to news from this website on September 3, Korean media etnews reported yesterday (local time) that Samsung Electronics and SK Hynix’s “HBM-like” stacked structure mobile memory products will be commercialized after 2026. Sources said that the two Korean memory giants regard stacked mobile memory as an important source of future revenue and plan to expand "HBM-like memory" to smartphones, tablets and laptops to provide power for end-side AI. According to previous reports on this site, Samsung Electronics’ product is called LPWide I/O memory, and SK Hynix calls this technology VFO. The two companies have used roughly the same technical route, which is to combine fan-out packaging and vertical channels. Samsung Electronics’ LPWide I/O memory has a bit width of 512

Kingbang launches new DDR5 8600 memory, offering CAMM2, LPCAMM2 and regular models to choose from Kingbang launches new DDR5 8600 memory, offering CAMM2, LPCAMM2 and regular models to choose from Jun 08, 2024 pm 01:35 PM

According to news from this site on June 7, GEIL launched its latest DDR5 solution at the 2024 Taipei International Computer Show, and provided SO-DIMM, CUDIMM, CSODIMM, CAMM2 and LPCAMM2 versions to choose from. ▲Picture source: Wccftech As shown in the picture, the CAMM2/LPCAMM2 memory exhibited by Jinbang adopts a very compact design, can provide a maximum capacity of 128GB, and a speed of up to 8533MT/s. Some of these products can even be stable on the AMDAM5 platform Overclocked to 9000MT/s without any auxiliary cooling. According to reports, Jinbang’s 2024 Polaris RGBDDR5 series memory can provide up to 8400

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

DDR5 MRDIMM and LPDDR6 CAMM memory specifications are ready for launch, JEDEC releases key technical details DDR5 MRDIMM and LPDDR6 CAMM memory specifications are ready for launch, JEDEC releases key technical details Jul 23, 2024 pm 02:25 PM

According to news from this website on July 23, the JEDEC Solid State Technology Association, the microelectronics standard setter, announced on the 22nd local time that the DDR5MRDIMM and LPDDR6CAMM memory technical specifications will be officially launched soon, and introduced the key details of these two memories. The "MR" in DDR5MRDIMM stands for MultiplexedRank, which means that the memory supports two or more Ranks and can combine and transmit multiple data signals on a single channel without additional physical The connection can effectively increase the bandwidth. JEDEC has planned multiple generations of DDR5MRDIMM memory, with the goal of eventually increasing its bandwidth to 12.8Gbps, compared with the current 6.4Gbps of DDR5RDIMM memory.

Lexar God of War Wings ARES RGB DDR5 8000 Memory Picture Gallery: Colorful White Wings supports RGB Lexar God of War Wings ARES RGB DDR5 8000 Memory Picture Gallery: Colorful White Wings supports RGB Jun 25, 2024 pm 01:51 PM

When the prices of ultra-high-frequency flagship memories such as 7600MT/s and 8000MT/s are generally high, Lexar has taken action. They have launched a new memory series called Ares Wings ARES RGB DDR5, with 7600 C36 and 8000 C38 is available in two specifications. The 16GB*2 sets are priced at 1,299 yuan and 1,499 yuan respectively, which is very cost-effective. This site has obtained the 8000 C38 version of Wings of War, and will bring you its unboxing pictures. The packaging of Lexar Wings ARES RGB DDR5 memory is well designed, using eye-catching black and red color schemes with colorful printing. There is an exclusive &quo in the upper left corner of the packaging.

Longsys displays FORESEE LPCAMM2 notebook memory: up to 64GB, 7500MT/s Longsys displays FORESEE LPCAMM2 notebook memory: up to 64GB, 7500MT/s Jun 05, 2024 pm 02:22 PM

According to news from this website on May 16, Longsys, the parent company of the Lexar brand, announced that it will demonstrate a new form of memory - FORESEELPCAMM2 at CFMS2024. FORESEELPCAMM2 is equipped with LPDDR5/5x particles, is compatible with 315ball and 496ball designs, supports frequencies of 7500MT/s and above, and has product capacity options of 16GB, 32GB, and 64GB. In terms of product technology, FORESEELPCAMM2 adopts a new design architecture to directly package 4 x32LPDDR5/5x memory particles on the compression connector, realizing a 128-bit memory bus on a single memory module, providing a more efficient packaging than standard memory modules.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

See all articles