PDA

Click to See Complete Forum and Search --> : A few questions....


MartinSmith
Aug 17th, 2003, 07:12 AM
Having recently invested in ASP.Net \ C# I have a few questions which I am sure will be no-brainers to anyone who has worked with the product for a while but which aren't immediately obvious to me from the documentation...

1) Is there any equivalent of the With ... End With construct in C#?

2) What is the best way of dealing with functions used in different pages? In Classic ASP I used an include file containing all these helper functions so all I needed to do was include the file and call SomeFunction directly.

In C# is there any better way than making all my Functions members of a CommonFunctions class, creating an instance at page level with

private CommonFunctions CF = new CommonFunctions();

and then calling CF.SomeFunction()


3) In ADO.Net is there any way to get the RecordCount from an OleDbDataReader or DataSet without having to loop through it?

4) Fairly frequently immediately after rebuilding a project I get an "access denied" error when viewing it in a browser. The only solution I have found to this thus far is rebooting my computer is there an easier way (I have tried just restarting IIS to no avail)?


Cheers,

Martin

hellswraith
Aug 17th, 2003, 10:37 AM
Originally posted by MartinSmith
Having recently invested in ASP.Net \ C# I have a few questions which I am sure will be no-brainers to anyone who has worked with the product for a while but which aren't immediately obvious to me from the documentation...

1) Is there any equivalent of the With ... End With construct in C#?

2) What is the best way of dealing with functions used in different pages? In Classic ASP I used an include file containing all these helper functions so all I needed to do was include the file and call SomeFunction directly.

In C# is there any better way than making all my Functions members of a CommonFunctions class, creating an instance at page level with

private CommonFunctions CF = new CommonFunctions();

and then calling CF.SomeFunction()


3) In ADO.Net is there any way to get the RecordCount from an OleDbDataReader or DataSet without having to loop through it?

4) Fairly frequently immediately after rebuilding a project I get an "access denied" error when viewing it in a browser. The only solution I have found to this thus far is rebooting my computer is there an easier way (I have tried just restarting IIS to no avail)?


Cheers,

Martin
1. Not in C#, only in VB.Net as far as I know.

2. What I do, if the functions don't require an instance of the object, then you create the class, make the constructor private instead of public and you can't create an instance of the class. Then, your methods will be labeled as static. Example:

private MyClass()
{
}

public static void MyMethod(string arguments)
{
}

Then, you just call it from your pages like so:
MyClass.MyMethod(somestring);
That way takes at least the creating an instance line of code away.

3. I don't know a way with the reader object, but with the dataset you can do ds.Tables[0].Rows.Count to get the number of records.

4. I haven't had that problems, so I don't know what to tell you, sorry.

MartinSmith
Aug 18th, 2003, 02:27 AM
Thanks very much! :)