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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.