当前位置:网站首页>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 .
边栏推荐
- Door level modeling - after class exercises
- Matplotlib常用設置
- 学成在线案例实战
- 【C#】依赖注入及Autofac
- Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
- How to display real-time 2D map after rviz is opened
- 在长城证券上买基金安全吗?
- Kubernetes resource object introduction and common commands (III)
- 物联网应用技术专业是属于什么类
- excel如何打开100万行以上的csv文件
猜你喜欢
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
Paramètres communs de matplotlib
2021 RoboCom 世界机器人开发者大赛-高职组初赛
MySQL binlog cleanup
Concurrentskiplistmap -- principle of table skipping
Zero foundation tutorial of Internet of things development
2021 robocom world robot developer competition - semi finals of higher vocational group
【ES实战】ES上的安全性运行方式
Algolia's search needs are almost closed
有没有一段代码,让你为人类的智慧所折服
随机推荐
常见的积分商城游戏类型有哪些?
JS - use of arguments
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
软件架构的本质
VIM color the catalogue
sql 优化
股票开户哪个证券公司最好,有安全保障吗
写给当前及未来博士研究生一些建议整理分享
为什么PHP叫超文本预处理器
JPA handwritten SQL, received with user-defined entity classes
Stm32f030f4 drives tim1637 nixie tube chip
Switch to software testing, knowing these four points is enough!
ARP message header format and request flow
cookie、session、tooken
云信小课堂 | IM及音视频中常见的认知误区
Concepts of dictionary, hash table and array
Yunxin small class | common cognitive misunderstandings in IM and audio and video
【C#】依赖注入及Autofac
Overview of edge calculation
Openwrt enable kV roaming