473,804 Members | 3,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling Stored SQL Function from asp.net how?

I put this in the microsoft.publi c.dotnet.langue ages.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.SqlCo mmand("R_Siphon DetailForDays",
sCon) sqlCmd.CommandT ype = CommandType.Sto redProcedure
sqlCmd.Paramete rs.Add("@sDate" , Session("Date") )
sqlCmd.Paramete rs.Add("@sDate2 ", Session("Date") ) rdr =
sqlCmd.ExecuteR eader(CommandBe havior.Default)
DataGrid1.DataS ource = rdr
DataGrid1.DataB ind()
T-SQL Stored Function

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


Nov 21 '05 #1
2 19475
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.SqlCo mmand("SELECT * FROM dbo.R_SiphonDet ailForDays",
sCon)

Also I would get rid of this line:

sqlCmd.CommandT ype = CommandType.Sto redProcedure

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" <da*****@netins .net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I put this in the microsoft.publi c.dotnet.langue ages.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.SqlCo mmand("R_Siphon DetailForDays",
sCon) sqlCmd.CommandT ype = CommandType.Sto redProcedure
sqlCmd.Paramete rs.Add("@sDate" , Session("Date") )
sqlCmd.Paramete rs.Add("@sDate2 ", Session("Date") ) rdr =
sqlCmd.ExecuteR eader(CommandBe havior.Default)
DataGrid1.DataS ource = rdr
DataGrid1.DataB ind()
T-SQL Stored Function

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

Nov 21 '05 #2

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

chanmm

"Roger" <da*****@netins .net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I put this in the microsoft.publi c.dotnet.langue ages.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.SqlCo mmand("R_Siphon DetailForDays",
sCon) sqlCmd.CommandT ype = CommandType.Sto redProcedure
sqlCmd.Paramete rs.Add("@sDate" , Session("Date") )
sqlCmd.Paramete rs.Add("@sDate2 ", Session("Date") ) rdr =
sqlCmd.ExecuteR eader(CommandBe havior.Default)
DataGrid1.DataS ource = rdr
DataGrid1.DataB ind()
T-SQL Stored Function

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



Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5790
by: Bob Murdoch | last post by:
I have an ASP application that calls a COM function to create a custom report as an Excel file. This works in a synchronous fashion, as long as the report does not take too long to create. If that happens, the session times out and we run into other kinds of problems. I have, in other cases, executed a stored procedure asynchronously (thanks to a tip from this group) thru ADO. I'm wondering if ASP provides some way of executing a...
4
11647
by: Mario Pranjic | last post by:
Hi! I have a scalar function that returns integer: xview (int) Now, I'm trying to build a procedure that has the following select inside: select atr1, xview(atr2) from tablename
3
41075
by: Clausmeyer | last post by:
I want to execute a dynamically generated sql-statement from inside an user-defined-function. Calling functions and extended stored-procs is allowed so I tried sp_executesql as well as sp_prepare/sp_execute .... but both fail with an error 'only functions and extended stored-procs may be called from inside a function.' any idea where I might be wrong ?
1
2541
by: Lauren Quantrell | last post by:
I'm using an Access2K front end on a SQL Server2K backend. I use Scope_Identity() in a lot of stored procedures to pass the newwly inserted record's unique ID to the next select statement in the same stored procedure. What I'm wondering is how I can pass the Scope_Identity back to the calling application. I'm hoping someone can show me the SP code and the aceess code needed to accomplish the following: I insert a new record in a table...
6
3315
by: jchao123 | last post by:
Dear All, I have an MDB file (Access 2000/XP) which contains generic routines I use in various apps (eg, API calls, File access classes etc). I have compiled into an MDE file which I reference in VBA from my other Access applications. This works fine and I'm quite happy with it... except for one area; error handling. In most of my functions I call an error handler which
5
2643
by: Zlatko Matić | last post by:
Hello. How can I call some functions on MSDE when working in .mdb ? Especially in-line functions which are similar to stored procedures. How can I use MSDE in-line functions as recordsource for .mdb forms ? Can I call in-line functions using ADO ? I tried, but it seems that only stored procedures are allowed (adCmdStoredProc).... Thanks.
2
1434
by: singlal | last post by:
Hi, my question was not getting any attention because it moved to 2nd page; so posting it again. Sorry for any inconvenience but I need to get it resolved fast. Need your help! **************************************************************************************************** Original Question: -------------------- Has anyone called a COBOL subroutine using COBOL CALL from a COBOL/DB2
0
1501
by: klove1209 | last post by:
Good afternoon. I need assistance with calling a function on the back end, that takes paremeters for a stored procedure. Then, that function returns the recordset back to the main DB. Below is the code for the procedures on the back and, and what I have so far on the front end. **This function calls the stored query, with given parameters, and returns the recodset** Public Function RSFromParameterQuery(strMonthYear As Date, strCase As...
0
1147
by: klove1209 | last post by:
Good afternoon. I need assistance with calling a function on the back end, that takes paremeters for a stored procedure. Then, that function returns the recordset back to the main DB. Below is the code for the procedures on the back and, and what I have so far on the front end. **This function calls the stored query, with given parameters, and returns the recodset** Public Function RSFromParameterQuery(strMonthYear As Date, strCase As...
0
10335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.