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)