PC Review


Reply
Thread Tools Rate Thread

Calling Stored SQL Function from asp.net how?

 
 
Roger
Guest
Posts: n/a
 
      22nd Mar 2005
I put this in the microsoft.public.dotnet.langueages.vb.data newsgroup, but
noticed there aren't alot of people there frequently like this newsgroup.
So I thought I would try here.

I get an error stating this call is to a function not a stored procedure?
How do I call a stored function in SQL Server from vb.net

Thanks....


asp.Net Code..... (VB)

sqlCmd = New SqlClient.SqlCommand("R_SiphonDetailForDays",
sCon) sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.Add("@sDate", Session("Date"))
sqlCmd.Parameters.Add("@sDate2", Session("Date")) rdr =
sqlCmd.ExecuteReader(CommandBehavior.Default)
DataGrid1.DataSource = rdr
DataGrid1.DataBind()


T-SQL Stored Function

ALTER FUNCTION dbo.R_SiphonDetailForDays
(
@sDate nvarchar(10),
@sDate2 nvarchar(10)
)
RETURNS TABLE
AS
RETURN ( SELECT SiteNum, FileDate, FileName, FileExt, FileSize
FROM a_SiphonDetail
WHERE (FileDate > CONVERT(smalldatetime, CONVERT(varchar(10),
DATEADD(day, - 1, @sdate), 101)) + '10:00 PM') AND (FileDate <
CONVERT(smalldatetime,
CONVERT(varchar(10), @sdate2), 101) + '10:00
PM') )




 
Reply With Quote
 
 
 
 
Michael C#
Guest
Posts: n/a
 
      22nd Mar 2005
Not too familiar with calling functions from VB.NET, although in general you
would use a function to return a scalar value. When calling functions, you
usually want to add dbo. to the front:

' Un-tested, but what the heck?
sqlCmd = New SqlClient.SqlCommand("SELECT * FROM dbo.R_SiphonDetailForDays",
sCon)

Also I would get rid of this line:

sqlCmd.CommandType = CommandType.StoredProcedure

Try that. If it doesn't work, I would just turn your UDF into an SP and
call it. That might be your easiest solution...

"Roger" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I put this in the microsoft.public.dotnet.langueages.vb.data newsgroup, but
> noticed there aren't alot of people there frequently like this newsgroup.
> So I thought I would try here.
>
> I get an error stating this call is to a function not a stored procedure?
> How do I call a stored function in SQL Server from vb.net
>
> Thanks....
>
>
> asp.Net Code..... (VB)
>
> sqlCmd = New SqlClient.SqlCommand("R_SiphonDetailForDays",
> sCon) sqlCmd.CommandType = CommandType.StoredProcedure
> sqlCmd.Parameters.Add("@sDate", Session("Date"))
> sqlCmd.Parameters.Add("@sDate2", Session("Date")) rdr =
> sqlCmd.ExecuteReader(CommandBehavior.Default)
> DataGrid1.DataSource = rdr
> DataGrid1.DataBind()
>
>
> T-SQL Stored Function
>
> ALTER FUNCTION dbo.R_SiphonDetailForDays
> (
> @sDate nvarchar(10),
> @sDate2 nvarchar(10)
> )
> RETURNS TABLE
> AS
> RETURN ( SELECT SiteNum, FileDate, FileName, FileExt, FileSize
> FROM a_SiphonDetail
> WHERE (FileDate > CONVERT(smalldatetime, CONVERT(varchar(10),
> DATEADD(day, - 1, @sdate), 101)) + '10:00 PM') AND (FileDate <
> CONVERT(smalldatetime,
> CONVERT(varchar(10), @sdate2), 101) +
> '10:00
> PM') )
>
>
>
>



 
Reply With Quote
 
chanmmn
Guest
Posts: n/a
 
      24th Mar 2005

http://msdn.microsoft.com/library/de.../html/daab.asp

chanmm

"Roger" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I put this in the microsoft.public.dotnet.langueages.vb.data newsgroup, but
> noticed there aren't alot of people there frequently like this newsgroup.
> So I thought I would try here.
>
> I get an error stating this call is to a function not a stored procedure?
> How do I call a stored function in SQL Server from vb.net
>
> Thanks....
>
>
> asp.Net Code..... (VB)
>
> sqlCmd = New SqlClient.SqlCommand("R_SiphonDetailForDays",
> sCon) sqlCmd.CommandType = CommandType.StoredProcedure
> sqlCmd.Parameters.Add("@sDate", Session("Date"))
> sqlCmd.Parameters.Add("@sDate2", Session("Date")) rdr =
> sqlCmd.ExecuteReader(CommandBehavior.Default)
> DataGrid1.DataSource = rdr
> DataGrid1.DataBind()
>
>
> T-SQL Stored Function
>
> ALTER FUNCTION dbo.R_SiphonDetailForDays
> (
> @sDate nvarchar(10),
> @sDate2 nvarchar(10)
> )
> RETURNS TABLE
> AS
> RETURN ( SELECT SiteNum, FileDate, FileName, FileExt, FileSize
> FROM a_SiphonDetail
> WHERE (FileDate > CONVERT(smalldatetime, CONVERT(varchar(10),
> DATEADD(day, - 1, @sdate), 101)) + '10:00 PM') AND (FileDate <
> CONVERT(smalldatetime,
> CONVERT(varchar(10), @sdate2), 101) +
> '10:00
> PM') )
>
>
>
>





 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method of calling a function where function name is stored in a variable or control Tony Vrolyk Microsoft Access VBA Modules 9 12th Jul 2007 07:20 PM
Method of calling a function where function name is stored in a variable or control Bob Quintal Microsoft Access 2 11th Jul 2007 08:49 PM
calling oracle stored function with CLOB parameter Jlorga Microsoft Excel Programming 0 3rd Mar 2006 11:58 AM
Calling stored procedures like any other function =?Utf-8?B?TWlrZQ==?= Microsoft ADO .NET 3 2nd Oct 2005 09:44 PM
Calling function within stored procedure EManning Microsoft Access ADP SQL Server 0 18th May 2004 02:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:24 PM.