方法一:
public class datasettoxml : inherits system.web.ui.page
private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
dim objconn as sqlconnection
dim strsql as string
strsql = "select top 10 * from customers"
objconn = new sqlconnection(configurationsettings.appsettings("connectionstring"))
dim sdacust as new sqldataadapter(strsql, objconn)
dim dstcust as new dataset()
sdacust.fill(dstcust, "customers")
save data to xml file and schema file
dstcust.writexml(server.mappath("customers.xml"),xmlwritemode.ignoreschema)
dstcust.writexmlschema(server.mappath("customers.xsd"))
end sub
这种方法是写入一个xml文件
方法二:
<webmethod(description:="所有教室列表")> _
public function listallrooms() as xmldocument
try
m_cpcoursearrange.fillroomid(m_dscoursearrange)
dim reader as new memorystream
dim doc as new xmldocument
doc.loadxml(m_dscoursearrange.getxml.tostring)
return doc
catch ex as protocols.soapexception
throw soapexceptione.raiseexception("listallrooms", "http://tempuri.org/coursearrange", ex.message, "4000", ex.source, soapexceptione.faultcode.server)
end try
end function
getxml--returns the xml representation of the data stored in the dataset. (msdn)
private shared sub demonstrategetxml()
create a dataset with one table containing two columns and 10 rows.
dim ds as dataset = new dataset("mydataset")
dim t as datatable = ds.tables.add("items")
t.columns.add("id", type.gettype("system.int32"))
t.columns.add("item", type.gettype("system.string"))
add ten rows.
dim r as datarow
dim i as integer
for i = 0 to 9
r = t.newrow()
r("id") = i
r("item")= "item" & i
t.rows.add(r)
next
display the dataset contents as xml.
console.writeline( ds.getxml() )
end sub
看来以后用dataset传递的时候也不用为它的转换发愁了。
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




