vb6调用带日期参数的存储过程

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
   tmpCm.Parameters.Append tmpPara
   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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值