Showing posts with label aspnet. Show all posts
Showing posts with label aspnet. Show all posts

Wednesday, March 28, 2012

How to use views in ASP.NET 2005

Hi,

I have created some views of the select join query in sql server 2005.

I want to make use of this views with the asp.net 2005 with C# code.

I m using SQLDATASOURCE to retrieve data from sqlserver.

Can anyone help me how to write in C#

VIEW

SELECTCAST(LEFT(SalesReturnDate, 11)AS datetime)AS Date,SUM(TotalAmount)AS SalesreturnFROM dbo.dfh_SalesReturnHeaderGROUP BYCAST(LEFT(SalesReturnDate, 11)AS datetime)
 
This is the sample view how to connect it with asp.net C#,sqldatsource of 2005
Thanxs in adv.

Hi Krish,

Lets call your view as uvw_SalesReturns

You use it like a table

You can give a sql command text or create a stored procedure containing the statement and then call the stored procedure

Sql statement is

select [Date], SalesReturn From uvw_SalesReturns

You can edit the sqldatasource and give this sql statement.

Or you can open an sqlconnection and call an sqlcommand to do it yourself without using sqldatasource if you have N-Tier Architecture.

Happy programming,
Anton

Monday, March 26, 2012

how to use UDFs with asp.net

Hi there, i have a user defined function in my sql server so i can use from different pages. the question is, how do i call it from asp.net? can some one show me some code? and if u can, can u show me how to use it with data grid?
thanks.What does your UDF do? Does it return a Table value? You would treat the resultset the same way you would with any other table/stored procedure resultset.

I think more information is needed here.

Terri|||I am not aware that you can call a UDF from ADO.NET directly. You can call a stored procedure, and so perhaps you will need to wrap your UDF call in a stored procedure. More information about what the UDF does (and what it is returning) will help.|||my UDF returns a table, i have been reading some tutorials and books, and they say that "one of the advantages of using UDF is that it is possible to use it from many applications." however, i have been going nuts trying to find some help on how to code this.
if i cant use UDF, can i use stored procedures to retrive a table? i read that you can only update data with stored procedures, and that u get tables with UDF's...
thanks for your help guys.|||You can absolutely return tables from a stored procedure, and you can certainly call a stored procedure from ADO.NET on an ASP.NET page.

This link should help explain how to do it.|||thanks!|||And you can absolutely also call UDFs from ADO.NET on an ASP.NET page.


SELECT * FROM dbo.fnMyFunctionThatReturnsATable

But personally I wouldn't call the UDF directly. I'd make a stored procedure which calls the UDF.

Terri|||True, true. I have never used UDF's that way, but no reason you cannot. There is just not a CommandType.UserDefinedFunction...

Thanks!|||Hi All,

1. Here is an example of ASP.NET calling UDF returns a TABLE


http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=265546
Re: Calling a SQL 2k UDF from .aspx page

-- See Posted: 07-02-2003 02:11 AM

2. As for using it, you make a judgement call.

3. You can use sp to wrap your UDF: There is an example

-CREATE FUNCTION dbo.udf_Txt_SplitTAB
-CREATE PROCEDURE sp_SELECT_IN
to wrap UDF.
-private void ASP_NET_SELECT_IN (string IN_List_Values)
to call sp.


http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=280390
sql