Recordset Function

F

fpennisi

Hi all

I have started writing a web app in Visual Studio 2005 (using c#). I
am new to both C# and Visual Studio 2005.

I will start by telling you what I need and then how I would have done
it using classic ASP previously.

What I need:
- Within Visual Studio 2005 (c#) to create a reusable function within
a file that can essentially be included in all my other pages (IE add
an include file reference from a master page - Please tell me if this
is poor coding practice).
- From my desired page I want to be able to pass a SQL command to a
function contained within the included file. The function then needs
to return a recodset (accessing a SQL database).

How I would do it in classic ASP.
For arguments sake lets say I have a standard ASP file. That page
potentially contained one or more include files. The include files
contain various functions so that I could reuse them within various
other pages (oo or modular coding).

For example:
I had a page where i wanted to display users. I would create a
standard ASP page and then using include file I would reference
functions from the included file(s). Essentially I would parse a SQL
stored procedure and its parameters or a SQL command (in a string
format) from the users page, make a connection and return a recodset.
Then draw the page as per my recordset or required.

How do I do this in C# (within visual studio 2005)?

Please suggest common/best practice methodolgies and teminology.
Providing code examples would be great.

Thanks in advance.

Fabio
 
M

Mark Rae [MVP]

How do I do this in ASP.NET / C# (within visual studio 2005)?

Firstly, ASP.NET does not use include files. For reusable markup etc, create
a UserControl. For reusable code, create a class.
http://www.google.co.uk/search?sour...4GGIH_en-GBGB220GB220&q="ASP.NET"+UserControl
http://www.google.co.uk/search?sour...TF-8&rlz=1T4GGIH_en-GBGB220GB220&q="C#"+class

Secondly, ASP.NET does not use ADO, so you can forget all about Recordsets.
ASP.NET uses ADO.NET.
http://www.google.co.uk/search?sour...UTF-8&rlz=1T4GGIH_en-GBGB220GB220&q="ADO.NET"

Thirdly, ASP.NET has a whole range of data-aware controls which remove
(almost) all of the tedious looping through rows of data and writing out
tables manually. In the above case, you will almost certainly want to use a
GridView.
http://aspnet101.com/aspnet101/tutorials.aspx?id=51

The above is absolutely fundamental to ASP.NET, so I would respectfully
suggest that you do the following:

1) Forget everything you ever knew about ASP Classic - ASP.NET is completely
different in virtually every way...

2) Get a copy of this:
http://www.amazon.com/Beginning-ASP...0590346?ie=UTF8&s=books&qid=1191239485&sr=1-3
and work all of the way through it...
 
K

Kevin Spencer

Hi Fabio,

You have quite a learning curve to surmount if you want to use ASP.Net. It
is a completely different programming model from ASP Classic. To begin with,
it is truly and fully object-oriented, not procedural. It does not use COM,
which is a pseudo-object-oriented technology, but the .Net Framework, which
is truly and fully object-oriented. If you've never worked with true OOP, I
suggest that you start by familiarizing yourself with OOP programming
principles. Here's a good place to start:

http://en.wikipedia.org/wiki/Object-oriented_programming

Now, assuming that you're willing to do the work necessary to use ASP.Net,
that is, to study up on the technology and teach yourself a new way of
thinking about programming, here are a few web sites that can help you get
started with ASP.Net:

http://www.asp.net/
http://www.w3schools.com/aspnet/default.asp
http://msdn2.microsoft.com/en-us/asp.net/default.aspx

It is indeed quite a learning curve, and you have the choice of sticking
with Classic ASP. But the rewards for learning and adapting ASP.Net and
object-oriented programming are many. Once you have learned how to leverage
OOP and the ASP.Net design model and practices, you will be able to create
web applications quickly, and manage them much more easily and effectively.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
S

sloan

1. Asp.Net is not Asp.
2. See rule #1.
3. When you need to display collections of information, do not use a looper
and Response.Write.
(See controls like the GridView, Repeater and DataList)
4. Get rid of the "include file" mentality.

5. Create assemblies that your web applications can ~use (and not
"include"). You do this by reference the assembly.

6. ADO.NET is Not Ado.
7. See #6. Do a google search for "IDataReader DataSet", and you'll start
seeing the differences.


Here is some advice:

Download this project code:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!140.entry

And then add a Web Application to the Solution.
Add a refernce to the BusinessLogic layer (in your newly created Web
Application)
Add a page (CustomersShowAll.aspx or something like that) to show "All
Customers", inside of a GridView and/or Repeater.

You'll need to make a call to this class/method

CustomerController.CustomersGetAllNoOrders()


After you get that working, put a button on that GridView, so when you
select it, you go to a another page.
CustomerEdit.aspx
and use
CustomerController.CustomerGetSingle(string customerId)
to bring up a single customer, and populate TextBoxes, DropDown list, combo
box whatever you need.


If you can get that far, then you will have learned a tremendous amount
getting past the Asp thinking, into Asp.Net.


I'm trying to be firm with my advice, because I wish 1000 times over,
someone would have done that with me when I made the jump.

...........


Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top