Results 1 to 5 of 5

Thread: Dataset always connected? [Resolved]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Dataset always connected? [Resolved]

    I have the code below, adapted from a book, in Sub New() of a form. It's used to populate some textboxes, and works fine (so far). The eventual aim is to have Next and Previous buttons to navigate the dataset.
    But I don't see where the connection is ever closed. I'd rather have the dataset retrieve records, close the connection and re-open it for each separate click event. There could be upwards of 20 users at one time, so I don't want a permanent connection.
    Should the code be in a stand alone sub, use a static variable, or what? Thanks.
    Last edited by salvelinus; Dec 19th, 2003 at 03:28 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    Wouldn't you just use an ADO.NET disconnected dataset? That way you would open the connection, fill the dataset, close the connection, and not reopen it until you need to refresh the date (or save changes, if that's a possibility).

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Declare a member static variable of your connection obj . Then , declare create two methods , OpenDB() and CloseDB() . Both work like this :

    VB Code:
    1. If connObj.State = ConnectionState.Closed Then 'Change Closed to Open in CloseDB() method .
    2. connObj.Open()
    3. End If

    Tip : Close the connection to the source after you're done.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    For the Next , Previous , Last , First navigations , try this demo .
    Attached Files Attached Files

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Thanks. Never used ado.net before a couple days ago, or vb.net before end of last week. Worked in vb6 and eVB for a couple years.

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