时间: 2021-07-31 作者:daque
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 oledbdataadapterdim 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.originalend sub(消息整治来自msdn)