sqlce資料操作vb例程
imports system.data
imports system.data.sqlserverce
imports system.io
''''
'''' 建立資料庫
''''
''''
sub createdb()
ifnot file.exists(datasource) then
dim sqlengine as
new sqlceengine("data source=\storage card\jichao.sdf")
sqlengine.createdatabase()
dim cmd as
new sqlcecommand("create table phone(name nvarchar(20) primary key not null,number nvarchar(20))", sqlce)
sqlce.open()
cmd.executenonquery()
sqlce.close()
endifend
subsub adddata()
tryif file.exists(datasource) then
dim cmd as
new sqlcecommand("", sqlce)
sqlce.open()
cmd.commandtext = "insert into phone(name,number) values ('abcde','12345')"
cmd.executenonquery()
cmd.commandtext = "insert into phone(name,number) values ('bcdef','23456')"
cmd.executenonquery()
cmd.commandtext = "insert into phone(name,number) values ('abcdx','12ds5')"
cmd.executenonquery()
cmd.commandtext = "insert into phone(name,number) values ('bcdet','23sdfa56')"
cmd.executenonquery()
sqlce.close()
endifcatch
sqlce.close()
endtryend
sub'顯示資料庫中的資料
sub list()
if file.exists(datasource) then
sqlce.open()
dim reader as sqlcedatareader
dim cmd as
reader = cmd.executereader
me.txbtest.text = ""
while reader.read
& "型別:" & reader.item("tmnl_type") & vbcrlf
endwhile
sqlce.close()
else
'status = status + "資料庫尚未建立!" & vbcrlf
endif
endsub
'刪除資料庫的資料
sub deletedata()
if file.exists(datasource) then
sqlce.open()
dim cmd as
new sqlcecommand("delete from phone", sqlce)
cmd.executenonquery()
sqlce.close()
me.txbtest.text = me.lbmsgshow.text + "資料庫的記錄已經刪除!" & vbcrlf
else
me.txbtest.text = me.lbmsgshow.text + "資料庫尚未建立!" & vbcrlf
endifend
sub'修改資料庫的資料
sub modifydata()
if file.exists(datasource) then
dim cmd as
new sqlcecommand("update phone set name='hello', number='87654321' where name='abcde' and number='12345'", sqlce)
cmd.executenonquery()
sqlce.close()
me.txbtest.text = me.lbmsgshow.text + "資料庫的記錄已經修改!" & vbcrlf
else
me.txbtest.text = me.lbmsgshow.text + "資料庫尚未建立!" & vbcrlf
endifend
sub
使用VB或VC操作Excel 2003(例程)
使用vb或vc操作excel 2003 例程 module module1 console.writeline press any key to continue console.readline end sub end module include using namespace std impo...
VB資料庫操作命令
連線資料庫 引用 microsoft activex data objects 2.8 library private sub form load dim cnn as adodb.connection set cnn new adodb.connection cnn.provider micros...
寫檔案操作 VB
寫檔案操作 public function writefile strwhat as string,strfilepath as string,strfilename as string as boolean writefile false dim fso as new filesystemobje...