VB動態產生建立sql檔案

2021-04-02 17:30:49 字數 2906 閱讀 1071

1) vb

生成sql檔案

vb為指定的表

sqlname

,動態產生建立觸發器

gps_insert

的sql

檔案,輸出到指定目錄檔案

sqlfile中。

public sub createsqlscriptfile(sqlfile as string, sqlname as string)

dim sql as string

open sqlfile for output as #1 '

開啟輸出檔案。

print #1, "if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[gps_insert]') and objectproperty(id, n'istrigger') = 1)"

print #1, "drop trigger [dbo].[gps_insert]"

print #1, "go"

print #1, "set quoted_identifier off"

print #1, "go"

print #1, "set ansi_nulls off"

print #1, "go"

print #1, "create trigger gps_insert"

print #1, "on "; sqlname

print #1, "for insert"

print #1, "as"

print #1, "begin"

print #1, "declare @gpsvid varchar(50)"

print #1, "declare @gp**obile varchar(50)"

print #1, "declare @gpsdate varchar(50)"

print #1, "declare @gpstime varchar(50)"

print #1, "declare @gpsdata varchar(50)"

print #1, "set nocount on"

print #1, "select @gp**obile =[f1],"

print #1, "   @gpsvid=[f2],"

print #1, "    @gpsdate=[f],"

print #1, "    @gpstime=[f4],"

print #1, "    @gpsdata=[f5]"

print #1, " from a as p inner join inserted as i"

print #1, " on p.f1 = i.f1"

print #1, " exec gps_datatrans gpsvid,@gp**obile,@gpsdate,@gpstime,@gpsdata"

print #1, " end"

print #1, " go"

print #1, " set quoted_identifier off"

print #1, " go"

print #1, " set ansi_nulls on"

print #1, " go"

close #1 '

關閉檔案。

end sub 2)

主要函式 vb

讀寫檔案要用到以下語句:1、

open

語句開啟檔案。

2、讀檔案使用

line input

、input #

,(以上為文字方式)和

get(以上為二進位制方式)。

3、寫檔案使用

print #

、write

(以上為文字方式)和

put(以上為二進位制方式)。4、

close

語句關閉檔案

5、二進位制方式下移動檔案位置使用

seek

語句。

open

"test.txt"

for

output

as #1 '

開啟輸出檔案。

print

#1, "this is a test" '

將文字資料寫入檔案。

print

#1, '

將空白行寫入檔案

print

#1, "tt"; tab ; "tt" '

資料寫入兩個區中間間隔

tab。

print

#1, "a"; " " ; "b" '

以空格隔開兩個字串。

print

#1, spc(2) ; "2 spaces " '

在字串之前寫入

2個空格。

print

#1, tab(5) ; "hello" '

將資料寫在第5列。

close

#1 '

關閉檔案。

讀檔案示例

使用line input #

語句從順序檔案中讀入一行資料,並將該行資料賦予乙個變數。本示例假設

testfile

檔案內含數行文字資料。

open

"test.txt

" for input as #1 '

開啟檔案。

do while not eof(#1) '

迴圈至檔案尾。

line input #1, strline '

讀入一行資料並將其賦予某變數。

debug.print strline '

在除錯視窗中顯示資料。

loop

close

#1 '

關閉檔案。

VB動態建立控制項

dim withevents mybtn as commandbutton set mybtn controls.add vb.commandbutton button1 with mybtn caption 我可以響應事件!width 1800 left 100 top 700 visible t...

VB6 動態建立使用者控制項

vb6有乙個新功能,可以動態新增控制項,不用控制項陣列 object.add progid,name,container 引數說明 object 必需的。乙個物件表示式,其值是 應用於 列表中的乙個物件。progid 必需的。乙個標識控制項的字串。大多數控制項的 progid 都可通過檢視物件瀏覽器...

在VB中動態建立資料庫

新建工程.新增控制項 對應寫上 private sub command2 click dim mydb as dao.database set mydb dao.opendatabase d mydb3.mdb dim d as string d delete from newtable1 mydb...