0

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?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by noamwegner
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

Edited by noamwegner: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.