从我的VB.Net App执行时,SQLServer存储过程不检索任何行,但检索SQLServer中的行 [英] SQLServer stored procedure retrieves no lines when executed from my VB.Net App, but retrieves lines in SQLServer
问题描述
你好,
我在VB.Net中遇到一个SQLDataAdapter有点问题
这是我的代码,大部分时间工作正常:
v_rrqAdapteur = 新跨度> SqlDataAdapter的(a_strRequete,m_cnxSQL)
v_rrqAdapteur.SelectCommand.CommandTimeout = <跨度类= 代码位> 900 跨度>
<跨度类= 代码关键字>如果 o_rrqTable 没什么 然后
o_rrqTable = 新 DataTable
结束 如果跨度>
v_rrqAdapteur.Fill(o_rrqTable)
v_rrqAdapteur.Dispose()
它也适用于查询是SQL存储过程的结果
exec dbo。[DocumentFiltresOptime] N ' Doc.TypeDocument in(2)';
但是在程序的参数中我使用的条件是date
exec dbo。[DocumentFiltresOptime] N ' (2)中的Doc.TypeDocument和(Doc.DateCreation> ''2015/04/09'')';
查询在SQLServerManager中执行时返回尝试的结果,但是当它返回时没有行它是由我的VB.Net应用程序执行的。
我不明白为什么。
可能有人解释这个神秘的原因?
非常感谢那些帮助的人。
您不需要将命令类型设置为存储过程,因为您的查询已包含EXEC。如果从SQL管理工作室执行时相同的查询返回值,那么问题是日期格式尝试使用MMM的日期格式,例如
<$ p 。$ p> EXEC DBO在(2)和[DocumentFiltresOptime] N'Doc.TypeDocument(Doc.DateCreation> '' 2015 /月/ 09 '')';
我有解决方案:使用转换SQL函数,它允许我指定要使用的正确日期格式。
exec SquarBTP_2012.dbo。[DocumentFiltresOptime] N ' (2)中的Doc.TypeDocument和(Doc.DateCreation> CONVERT(date,''09/04 / 2015'',103))';
总是使用此函数给SQL提供日期,格式会有任何问题。
感谢M.Samad的好主意
Hello,
I've got a little problem with a SQLDataAdapter in VB.Net
Here's my code, working fine most of time :
v_rrqAdapteur = New SqlDataAdapter(a_strRequete, m_cnxSQL)
v_rrqAdapteur.SelectCommand.CommandTimeout = 900
If o_rrqTable Is Nothing Then
o_rrqTable = New DataTable
End If
v_rrqAdapteur.Fill(o_rrqTable)
v_rrqAdapteur.Dispose()
It works also when the query is the result of SQL Stored procedure
exec dbo.[DocumentFiltresOptime] N'Doc.TypeDocument in (2)';
but where in the argument of the procedure I use a condition of date
exec dbo.[DocumentFiltresOptime] N'Doc.TypeDocument in (2) and (Doc.DateCreation > ''2015/04/09'')';
The query return the attempted result when I execute it in SQLServerManager, but it return no lines when it's executed by my VB.Net App.
I don't understand why.
Could someone explain le the reason of this mystery ?
Thanks a lot for those who'll help.
You don't need to set the command type to stored procedure because your query already contains a 'EXEC' . If the same query is returning values when executing from SQL management studio, then the problem is with the date format try using date format with MMM, for example
exec dbo.[DocumentFiltresOptime] N'Doc.TypeDocument in (2) and (Doc.DateCreation > ''2015/Apr/09'')';
I've got the solution : use the "convert" SQL function, which allows me to specify the right date format to use.
exec SquarBTP_2012.dbo.[DocumentFiltresOptime] N'Doc.TypeDocument in (2) and (Doc.DateCreation > CONVERT(date, ''09/04/2015'', 103))';
Always use this function to give dates to SQL, there will be any problem of format.
Thanks to M.Samad for his good ideas
这篇关于从我的VB.Net App执行时,SQLServer存储过程不检索任何行,但检索SQLServer中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!