Results 1 to 2 of 2

Thread: sqlClient Connection [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    sqlClient Connection [RESOLVED]

    in vb, I use this to open a connection:
    VB Code:
    1. Public Sub Connect(ByVal db As SqlClient.SqlConnection)
    2.         'Overloaded
    3.         'This is for a sqlConnection
    4.         'Kill the connection if it is open
    5.         'Then open the connection
    6.  
    7.         KillConnection(db)
    8.         db.Open()
    9.  
    10.     End Sub
    11.     Public Sub KillConnection(ByVal DB As SqlClient.SqlConnection)
    12.         If DB.State <> ConnectionState.Closed Then
    13.             DB.Close()
    14.         End If
    15.     End Sub
    That ensures that a connection is closed beforehand. In c#, I'm trying the same:

    PHP Code:
    public void Connect(SqlConnection db)
            {
                
    KillConnection(db);
                
    db.Open;
            }


            public 
    void KillConnection(SqlConnection db)
            {
                if (
    db.State !=System.Data.ConnectionState.Closed)
                {
                    
    db.Open;
                }
            } 
    I'm getting build errors on the db.Open part.

    A couple of questions pop up for me. First, of course, is how do I get this to work?! Second, does this have something to do with the fact that Option Strict is on in C#? I know C# is more of a stronger typed language and I actually expected something like this to happen.
    Last edited by Andy; Aug 13th, 2004 at 12:08 PM.

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    in c# methods have ()
    you must ALWAYS put the ()

    so..

    Open();

    you'll see as it is MUCH better than in VB, that way you know if Open is a method or a variable just by looking at it
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width