954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Function

Hello!

I've got trivial problem and have no time to re-read manuals. I need to construct a function in SQL2005 which selects from DB and returns datatable. Something like this:

create function GetAllStudents()
returns Table
as
begin
(
select StudentID,StudentName,StudentFamilyName,Birthday,HisClass
from Students
)
return DataTable


I need it to bind then to bind to DataView Control on my ASP.Net 2.0 page.

Any help and advice?

Nfurman
Junior Poster in Training
69 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

why dont you use a stored proc
CREATE PROC blahProcName ()
{
AS
select StudentID,StudentName,StudentFamilyName,Birthday,HisClass
from Students
}
and on the server side
using system.data.sqlclinet;

sqlconnection conn = new sqlconnection(connectionstring);
conn.open;
sqlcommand cmd = new sqlcommand("blahProcName",conn);
cmd.commandType = commandType.storedproc;
dateTable dt = new dataTable("mytable");
sqlAdapter sa = new sqlAdapter (cmd);
sa.fill(dt);
conn.close();
cmd.dispose();
sa.dipose();
then you can bind to the datatable
there is no need to use a function here and its very easy to use
hope it helped

noamwegner
Newbie Poster
12 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You