当前位置:网站首页>ADO. Net SqlDataAdapter object
ADO. Net SqlDataAdapter object
2022-07-01 23:42:00 【Quzhou Xiaofeng】
5.1 What is the SqlDataAdapter
5.1.2 Create and use SqlDataAdapter object
strSQL ="select * From tbname";
SqlConnection = new SqlConnection(strConnection);
SqlCommand = new SqlCommand(strSQL,cn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd
SqlDataAdapter Constructors
// Pass the connection string , This method will generate a new SqlConnection object
SqlDataAdapter da = new SqlDataAdapter(strSQL,strConnection);
// Transfer connection object
SqlDataAdapter da = new SqlDataAdapter(strSQL,cn);
// Pass on SqlCommand object
SqlCommand cmd = new SqlCommand(strSQL,cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
5.2.2 Get the results from the query
1. Use Fill() Method
call SqlDataAdapter Class Fill Method will be executed and stored in SqlDataAdapter Medium SqlCommand Queries in object properties , And store the results in DataSet.
The following code calls Fill Method , And display stored in DataSet Results in
// There is no time to sleep , Hurry up , Years do not bite , Time blows old .
strSQL ="select userName,userID From customers";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strSQL,strConnection);
da.Fill(ds);
foreach(DataRow row in ds.Tables[0].Rows)
Console.Write("{0} - {1}",Row["userID"],row["userName"]);
// there Fil Method implicit l Create a DataTable object , also TableName yes "Table"
The description of this value is poor , You can customize the filled tableName
SqlDataAdapter da = new SqlDataAdapter(strSQL,cn);
da.TableMappings.Add("Table","customers");// Add table name
DataSet ds = new DataSet();
da.Fill(ds);
Console.Write("Table ={0}",ds.Tables[0].TableName);
// You can also specify Fill Parameters , Do not add table names manually
5.2.2 Get the results from the query
4. Using overloaded Fill Method
strSQL ="Select * From customers";
SqlCommand cmd = new SqlCommand(strSQL,cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
foreach(DataRow row in dt.Rows)
Console.Write("{0}-{1}",row[1],row[2]);
use SqlDataAdapter Class Fill Method Pagination
// From the first record , fill 20 Record to "Products" Of DataTable in
SqlDataAdapter.Fill(DataSet,0,20,"Products");
// This method makes it easy to page queries , But its efficiency is relatively low .
边栏推荐
- Is there a piece of code that makes you convinced by human wisdom
- ARP message header format and request flow
- [understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
- 使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
- Matplotlib常用設置
- 2021 RoboCom 世界机器人开发者大赛-高职组复赛
- 深度学习 | 三个概念:Epoch, Batch, Iteration
- kubernetes资源对象介绍及常用命令(三)
- Commemorate becoming the first dayus200 tripartite demo contributor
- PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
猜你喜欢
ConcurrentSkipListMap——跳表原理
RPA教程01:EXCEL自动化从入门到实操
SWT / anr problem - SWT causes kernel fuse deadlock
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
Redis RDB snapshot
Use vb Net to convert PNG pictures into icon type icon files
De PIP. Interne. CLI. Main Import main modulenotfounderror: No module named 'PIP'
华为HMS Core携手超图为三维GIS注入新动能
2021 robocom world robot developer competition - semi finals of higher vocational group
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
随机推荐
Is it safe to choose mobile phone for stock trading account opening in Shanghai?
Future trend and development of neural network Internet of things
Know --matplotlib
MT manager test skiing Adventure
PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
ADO.NET 之sqlConnection 对象使用摘要
The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem
问题随记 —— file /usr/share/mysql/charsets/README from install of MySQL-server-5.1.73-1.glibc23.x86_64 c
[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
股票开户哪个证券公司最好,有安全保障吗
图的遍历之深度优先搜索和广度优先搜索
Redis 主从同步
软件架构的本质
Matplotlib常用图表
JPA handwritten SQL, received with user-defined entity classes
Matplotlib常用設置
小程序表单校验封装
Practical application and extension of plain framework
2021 RoboCom 世界机器人开发者大赛-高职组复赛
How to display real-time 2D map after rviz is opened