当前位置:网站首页>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 .
边栏推荐
- 2021 RoboCom 世界机器人开发者大赛-高职组复赛
- 2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
- Stm32f030f4 drives tim1637 nixie tube chip
- URL introduction
- 第六章 数据流建模
- 距离度量 —— 汉明距离(Hamming Distance)
- 安全协议重点
- SQL optimization
- dat. GUI
- PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
猜你喜欢

第六章 数据流建模

algolia 搜索需求,做的快自闭了...

Development trend and future direction of neural network Internet of things

2021 robocom world robot developer competition - preliminary competition of higher vocational group

What category does the Internet of things application technology major belong to

Linux foundation - centos7 offline installation of MySQL

门级建模—课后习题

ARP报文头部格式和请求流程

物联网应用技术专业是属于什么类

Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object
随机推荐
小程序表单校验封装
[LeetCode] 最后一个单词的长度【58】
距离度量 —— 汉明距离(Hamming Distance)
PostgreSQL source code (57) why is the performance gap so large in hot update?
Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object
[must] bm41 output the right view of the binary tree [medium +]
Postgresql随手记(10)动态执行EXECUTING语法解析过程
Kubernetes resource object introduction and common commands (III)
Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
from pip._internal.cli.main import main ModuleNotFoundError: No module named ‘pip‘
algolia 搜索需求,做的快自闭了...
Postgresql源码(57)HOT更新为什么性能差距那么大?
Practical application and extension of plain framework
vs2015 AdminDeployment.xml
TS初次使用、ts类型
Which securities company is the best to open a stock account? Is there a security guarantee
[C #] dependency injection and Autofac
Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
Matplotlib常用設置
cookie、session、tooken