oledbdataadapter 構(gòu)造
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)
參數(shù)
selectcommand oledbcommand,它是 select 語句或存儲過程,被設(shè)置為 oledbdataadapter 的 selectcommand 屬性。
selectcommandtext 一個字符串,它是 sql select 語句或?qū)⒂?oledbdataadapter 的 selectcommand 屬性使用的存儲過程。
selectconnection 表示連接的 oledbconnection。
selectconnectionstring 連接字符串。
備注
當(dāng)創(chuàng)建 oledbdataadapter 的實例時,下面的讀/寫屬性將設(shè)置為以下初始值。
properties
初始值
missingmappingaction
missingmappingaction.passthrough
missingschemaaction
missingschemaaction.add
可以通過單獨調(diào)用屬性來更改任何這些屬性的值。
示例
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)