vb6呼叫帶日期引數的儲存過程

2021-05-27 09:36:27 字數 1747 閱讀 4964

create table tmp

( fcode varchar(10),

fdate smalldatetime

)insert into tmp

select 'a1','2011-08-10' union all

select 'a2','2011-08-11' union all

select 'a3','2011-08-12' union all

select 'a4','2011-11-07' union all

select 'a5','2011-11-08' union all

select 'a6','2011-11-09'

go--drop proc sp_testdatepara

create proc sp_testdatepara(@date smalldatetime)

as select * from tmp where fdate=@date

/* exec sp_testdatepara '2011-08-11'

*/

以下vb**

option explicit

dim cn as new adodb.connection

'此方法不受當前日期格式

private sub command1_click()

dim strsql as string

dim rst as new adodb.recordset

dim tmpcm as new adodb.command

dim tmppara as adodb.parameter

tmpcm.activeconnection = cn

tmpcm.commandtype = adcmdstoredproc

tmpcm.commandtext = "sp_testdatepara"

set tmppara = new adodb.parameter

tmppara.name = "date"

tmppara.type = addbtimestamp

tmppara.value = date

tmppara.direction = adparaminput

set tmppara = nothing

set rst = tmpcm.execute()

set datagrid1.datasource = rst

end sub

'此方法會受當前日期格式

private sub command2_click()

dim strsql as string

dim rst as new adodb.recordset

strsql = "exec sp_testdatepara '" & date & "'"

rst.open strsql, cn, adopenstatic, adlockpessimistic

set datagrid1.datasource = rst

end sub

private sub form_load()

cn.cursorlocation = aduseclient

cn.connectionstring = "driver=sql server;server=.;uid=sa;pwd=123;database=pubs;"

cn.open

end sub

vb中呼叫帶引數的儲存過程

dim data connection as new adodb.connection ado連線物件 dim data recordset as new adodb.recordset ado的記錄集 dim sqlcmdcheckelement as new adodb.command dim ...

儲存過程如何呼叫帶引數的儲存過程

declare value varchar max exec tmfun getsearchstr 陝西 table1 name value output select from users where address value 顯示結果為 解釋 其中,tmfun getsearchstr 為儲存...

VB中呼叫帶引數儲存過程的實現 資料庫

vb中呼叫帶引數儲存過程的實現 資料庫 張永曉 vb做為快速應用開發 rad 工具越來越得到開發人員的認可和接受。它對許多api 如odbc api socket api等等 的封裝使得程式設計變得簡單起來。同時,它支援整合開發環境下的視覺化 事件驅動 物件導向等程式設計特點。下面,我們談談在vb中...