国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 邳州市| 新源县| 长武县| 宿松县| 漠河县| 大埔区| 子洲县| 徐水县| 察雅县| 寿阳县| 嘉鱼县| 普定县| 额尔古纳市| 永城市| 万荣县| 枣强县| 晋城| 昌都县| 龙里县| 驻马店市| 元江| 宝应县| 班玛县| 宁晋县| 禹州市| 南宫市| 肇东市| 昌邑市| 墨脱县| 卫辉市| 革吉县| 迭部县| 德阳市| 铜川市| 乌拉特前旗| 邯郸县| 巴东县| 宜兰县| 微山县| 正安县| 宣化县|