• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

ADO.NET对象的构造(1)_OleDbDataAdapter

发布: 2007-7-01 11:09 | 作者: admin | 来源: | 查看: 35次 | 进入软件测试论坛讨论

领测软件测试网 OleDbDataAdapter 构造



n Public Sub New()
n Public Sub New(ByVal selectCommand As OleDbCommand)

n Public Sub New(ByVal selectCommandText As String,ByVal selectConnection As OleDbConnection)

n Public Sub New(ByVal selectCommandText As String,ByVal selectConnectionString As String)



参数

selectCommand OleDbCommand,它是 SELECT 语句或存储过程,被设置为 OleDbDataAdapter 的 SelectCommand 属性。
selectCommandText 一个字符串,它是 SQL SELECT 语句或将由 OleDbDataAdapter 的 SelectCommand 属性使用的存储过程。
selectConnection 表示连接的 OleDbConnection。
selectConnectionString 连接字符串。


备注

当创建 OleDbDataAdapter 的实例时,下面的读/写属性将设置为以下初始值。

Properties
初始值

MissingMappingAction
MissingMappingAction.Passthrough

MissingSchemaAction
MissingSchemaAction.Add





可以通过单独调用属性来更改任何这些属性的值。



示例

Public Sub CreateOleDbDataAdapter()

Dim myOleDbConnection As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")



Dim custDA As OleDbDataAdapter = New OleDbDataAdapter



Dim myOleDbCommand As OleDbCommand = New OleDbCommand("SELECT CustomerID, CompanyName FROM CUSTOMERS", myOleDbConnection)

Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(myOleDbCommand)



Dim mySelectText As String = "SELECT CustomerID, CompanyName FROM CUSTOMERS"

Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(mySelectText, myOleDbConnection)



Dim mySelectText As String = "SELECT CustomerID, CompanyName FROM CUSTOMERS"

Dim myConnString As String = "Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"

Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(mySelectText, myConnString)



custDA.MissingSchemaAction = MissingSchemaAction.AddWithKey



custDA.SelectCommand = New OleDbCommand("SELECT CustomerID, CompanyName FROM CUSTOMERS", myOleDbConnection)

custDA.InsertCommand = New OleDbCommand("INSERT INTO Customers (CustomerID, CompanyName) VALUES (?, ?)", myOleDbConnection)

custDA.UpdateCommand = New OleDbCommand("UPDATE Customers SET CustomerID = ?, CompanyName = ? WHERE CustomerID = ?", myOleDbConnection)

custDA.DeleteCommand = New OleDbCommand("DELETE FROM Customers WHERE CustomerID = ?", myOleDbConnection)



custDA.InsertCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID")

custDA.InsertCommand.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName")



custDA.UpdateCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID")

custDA.UpdateCommand.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName")

custDA.UpdateCommand.Parameters.Add("@oldCustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original



custDA.DeleteCommand.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original

End Sub



(信息整理来自MSDN)

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网