Results 1 to 2 of 2

Thread: public string; public using

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    public string; public using

    i put the code below inside a Module but I encounter an error

    Code:
            public static string ConStr = "Provider=Microsoft.Jet.OleDB.4.0; Data Source =" + Application.StartupPath + "\\db1.mdb";
            public using (OleDbConnection Conn = new OleDbConnection(ConStr))
    what should I do?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: public string; public using

    You can only use a 'using' block with local variables. The whole point of a 'using' block is to create an object and dispose it at the end of the block. It wouldn't make sense to dispose an object assigned to a member variable immediately would it? You would get rid of the 'using' and just declare a regular old OleDbConnection variable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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