国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > XML > 正文

轉(zhuǎn)換DataSet到普通xml的新法

2024-09-05 20:55:52
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
大家知道,用dataset傳遞的webservice,微軟會(huì)在各個(gè)節(jié)點(diǎn)加上schema,所以無(wú)法與j2ee,flash兼容,所以我找到了一種轉(zhuǎn)換他們變成普通xml的方法。代碼如下:

方法一:
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

這種方法是寫(xiě)入一個(gè)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


看來(lái)以后用dataset傳遞的時(shí)候也不用為它的轉(zhuǎn)換發(fā)愁了。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 井研县| 嘉鱼县| 宾川县| 武邑县| 谢通门县| 前郭尔| 米脂县| 大兴区| 合作市| 内丘县| 泸溪县| 广元市| 汽车| 根河市| 桑植县| 南城县| 金华市| 北京市| 台江县| 蓬安县| 新宾| 许昌市| 嘉义县| 上饶市| 大足县| 武胜县| 涞水县| 通化县| 双城市| 于都县| 黑河市| 清水县| 边坝县| 海兴县| 平乐县| 吕梁市| 肇州县| 苏尼特右旗| 琼海市| 呼伦贝尔市| 安徽省|