Groups | Blog | Home
all groups > vb.net data > march 2005 >

vb.net data : Calling SQL 2000 Stored Function from VB.Net...


Roger
3/22/2005 8:49:07 AM
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') )


Michael C#
3/23/2005 10:26:57 AM
Wouldn't you need to specify the parameters in the CommandText also? Not
sure, I don't work with many UDF's from VB.NET:

sqlCmd.CommandText = "select * from R_SiphonDetailForDays (@sDate, @sDate2)"

[quoted text, click to view]

Stephany Young
3/23/2005 8:47:40 PM
Try
CommandType.Text and
ConmmandText = "select * from R_SiphonDetailForDays"

[quoted text, click to view]

AddThis Social Bookmark Button