<
%@ import
namespace="
system.data"%
>
<
%@ import
namespace="
system.data.oledb"%
>
<
html
>
<
head runat
=server
>
<
script language="
vb"runat="
server
">
function
convertdatareadertodataset(objreader
asoledbdatareader, name
asstring
) as
dataset
dimdataset
=new
dataset()
dimi
asinteger
dimdatarow
asdatarow
dimcolumn
asdatacolumn
dimcolumnname
asstring
dimschematable
asdatatable
=objreader.getschematable()
dimdatatable
asdatatable
=new
datatable(name)
'建立datatable的欄位名稱與資料型態
fori =0
toschematable.rows.count -1
datarow
=schematable.rows(i)
'取得欄位名稱
columnname
=datarow(
"columnname")
'新增到datatable物件
column
=new
datacolumn(columnname, datarow(
"datatype"))
datatable.columns.add(column)
'新增字段
next
dataset.tables.add(datatable)
'新增到dataset物件
'將datareader的記錄資料填入datatable
while
objreader.read()
datarow
=datatable.newrow()
fori =0
toobjreader.fieldcount -1
datarow(i)
=objreader.item(i)
next
datatable.rows.add(datarow)
datatable.acceptchanges()
'更改dataset物件
endwhile
return
dataset
end function
script
>
head
>
<
body
>
<
%dim
objcon
asoledbconnection
dimobjcmd
asoledbcommand
dimobjdatareader
asoledbdatareader
dimobjdataset
asdataset
dimobjcolumn
asdatacolumn
dimobjrow
asdatarow
dimi
asinteger
'oledb提供者字串
dimstrdbcon ="
provider=microsoft.jet.oledb.4.0;data source="&
"users.mdb")
'建立connection物件
objcon
=new
oledbconnection(strdbcon)
objcon.open()
'開啟資料庫鏈結
'建立command物件的sql指令
objcmd
=new
oledbcommand(
"select * from users
", objcon)
'取得datareader物件
objdatareader
=objcmd.executereader()
'將datareader轉換成dataset
objdataset
=convertdatareadertodataset(objdatareader,
"users")
'顯示dataset的記錄資料
response.write(""
)response.write(""
)for
each
objcolumn
inobjdataset.tables(
"users
").columns
response.write(
""&
objcolumn.columnname &"
")
next
response.write(
" "
)for
each
objrow
inobjdataset.tables(
"users
").rows
response.write(""
)for
each
objcolumn
inobjdataset.tables(
"users
").columns
ifobjrow.isnull(objcolumn)
=false
then
response.write(""
&objrow.item(objcolumn).tostring() &"
")else
response.write(
"---
")endif
next
response.write(
" "
)next
response.write(
" "
)objdatareader.close()
'關閉datareader
objcon.close()
'關閉資料庫鏈結
%>
body
>
html
>
DataReader 轉換成實體(或List)
datareader轉換為obj list 泛型 datareader 返回泛型型別 protected static ilistdatareader2obj sqldatareader rdr else obj.getproperty rdr.getname i setvalue t,tempva...
將string轉換成char
string 是c 標準庫裡面其中乙個,封裝了對字串的操作 把string轉換為char 有3中方法 1.data 如 如 string str abc char p str.data 2 c str 如 如 string str gdfd char p str.c str 3.copy 比如比如 ...
將數字轉換成漢語
public string numtochinese string x 為數字位數建立乙個位陣列 string p array digit new string 為數字單位建立乙個單位陣列 string p array units new string string p str returnvalu...