Click here to Skip to main content
15,915,501 members
Home / Discussions / C#
   

C#

 
GeneralRe: Regular expression help - end of text Pin
Guffa2-Aug-05 9:49
Guffa2-Aug-05 9:49 
GeneralRe: Regular expression help - end of text Pin
Luis Alonso Ramos2-Aug-05 10:00
Luis Alonso Ramos2-Aug-05 10:00 
Questionstatic class for database access? Pin
theStorminMormon2-Aug-05 8:58
theStorminMormon2-Aug-05 8:58 
AnswerRe: static class for database access? Pin
Guffa2-Aug-05 9:11
Guffa2-Aug-05 9:11 
GeneralRe: static class for database access? Pin
theStorminMormon2-Aug-05 9:14
theStorminMormon2-Aug-05 9:14 
GeneralRe: static class for database access? Pin
Luis Alonso Ramos2-Aug-05 9:32
Luis Alonso Ramos2-Aug-05 9:32 
GeneralRe: static class for database access? Pin
Guffa2-Aug-05 9:36
Guffa2-Aug-05 9:36 
AnswerRe: static class for database access? Pin
Luis Alonso Ramos2-Aug-05 9:13
Luis Alonso Ramos2-Aug-05 9:13 
theStorminMormon wrote:
if I were to create a static class (say DBController) and then attempt to use it to access my database (eg with the method DBController.getNewClients) then the method (getNewClients) would have to create non-static instances of objects (ie the connection object).

You can create instances of objects in static methods. The isntance with belong to the class and not to any instance. Like this:
class DBController
{
    static DBController()
    {
        conn = new SqlConnection(....);
    }
 
    public static Customer GetCustomer(int id)
    {
        conn.Open();

        SqlCommand cmd = new SqlCommand("...", conn);
        SqlDataReader rdr = cmd.ExecuteReader();
        rdr.Read();
 
        Customer customer = new Customer()
        customer.Name = (string) rdr["Name"];

        rdr.Close();
        conn.Close();
 
        return customer;
    }

    private static SqlConnection conn;
}
While is not precisely the prettiest code, it shows two things: A class can have static objects (in this case a connection that belongs to the class itslef, and not to objects of this class); and a static method can create and return instances of this or any other class.

I hope this helps!

-- LuisR




Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: static class for database access? Pin
theStorminMormon2-Aug-05 9:16
theStorminMormon2-Aug-05 9:16 
GeneralRe: static class for database access? Pin
Luis Alonso Ramos2-Aug-05 9:26
Luis Alonso Ramos2-Aug-05 9:26 
GeneralEmulate a twain interface Pin
Oliver Lange2-Aug-05 8:25
Oliver Lange2-Aug-05 8:25 
GeneralSupressing Security Error Dialog Pin
RB@Emphasys2-Aug-05 7:53
RB@Emphasys2-Aug-05 7:53 
GeneralRe: Supressing Security Error Dialog Pin
mav.northwind2-Aug-05 20:06
mav.northwind2-Aug-05 20:06 
GeneralRe: Supressing Security Error Dialog Pin
RB@Emphasys3-Aug-05 3:57
RB@Emphasys3-Aug-05 3:57 
GeneralRe: Supressing Security Error Dialog Pin
mav.northwind3-Aug-05 7:42
mav.northwind3-Aug-05 7:42 
GeneralCapturing The Build Date Into Code Pin
bneacetp2-Aug-05 7:22
bneacetp2-Aug-05 7:22 
GeneralRe: Capturing The Build Date Into Code Pin
hamster12-Aug-05 11:22
hamster12-Aug-05 11:22 
GeneralRe: Capturing The Build Date Into Code Pin
bneacetp2-Aug-05 14:13
bneacetp2-Aug-05 14:13 
GeneralRe: Capturing The Build Date Into Code Pin
hamster13-Aug-05 8:21
hamster13-Aug-05 8:21 
GeneralReordering DOCKED controls Pin
Radgar2-Aug-05 7:16
Radgar2-Aug-05 7:16 
GeneralRe: Reordering DOCKED controls Pin
Alomgir Miah2-Aug-05 7:21
Alomgir Miah2-Aug-05 7:21 
GeneralRe: Reordering DOCKED controls Pin
Judah Gabriel Himango2-Aug-05 10:33
sponsorJudah Gabriel Himango2-Aug-05 10:33 
GeneralRe: Reordering DOCKED controls Pin
Radgar2-Aug-05 13:11
Radgar2-Aug-05 13:11 
GeneralRe: Reordering DOCKED controls Pin
Judah Gabriel Himango2-Aug-05 16:19
sponsorJudah Gabriel Himango2-Aug-05 16:19 
GeneralRe: Reordering DOCKED controls Pin
Radgar2-Aug-05 16:27
Radgar2-Aug-05 16:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.