Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. connect to access database

connect to access database

Scheduled Pinned Locked Moved C#
database
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MemberDotNetting
    wrote on last edited by
    #1

    I want to retrieve the name of the database from a text box (datasource = txtdatabase.text), but the connection does not work. the connection is made ​​with the direct assignment of name database directly cnx = new OleDbConnection ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = D: \ \ mabase.mdb");

    class Connexion { static public OleDbConnection cnx; static bool ok; static public Boolean getConnexion() { if (cnx == null) { cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+datasource); try { cnx.Open(); ok = true; } catch (OleDbException) { ok = false; } } return ok; } }

    L 2 Replies Last reply
    0
    • M MemberDotNetting

      I want to retrieve the name of the database from a text box (datasource = txtdatabase.text), but the connection does not work. the connection is made ​​with the direct assignment of name database directly cnx = new OleDbConnection ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = D: \ \ mabase.mdb");

      class Connexion { static public OleDbConnection cnx; static bool ok; static public Boolean getConnexion() { if (cnx == null) { cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+datasource); try { cnx.Open(); ok = true; } catch (OleDbException) { ok = false; } } return ok; } }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      MemberDotNetting wrote:

      the connection does not work.

      And you know that it does not work because....?

      Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

      M 1 Reply Last reply
      0
      • L Lost User

        MemberDotNetting wrote:

        the connection does not work.

        And you know that it does not work because....?

        Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

        M Offline
        M Offline
        MemberDotNetting
        wrote on last edited by
        #3

        sorry?

        OriginalGriffO L 2 Replies Last reply
        0
        • M MemberDotNetting

          sorry?

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          He means "How do you know it doesn't work? Do you get an exception? If so, what is the message?" Your original question is vague, and not answerable. You need to provide better information.

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • M MemberDotNetting

            I want to retrieve the name of the database from a text box (datasource = txtdatabase.text), but the connection does not work. the connection is made ​​with the direct assignment of name database directly cnx = new OleDbConnection ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = D: \ \ mabase.mdb");

            class Connexion { static public OleDbConnection cnx; static bool ok; static public Boolean getConnexion() { if (cnx == null) { cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+datasource); try { cnx.Open(); ok = true; } catch (OleDbException) { ok = false; } } return ok; } }

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            catch (OleDbException)
            {
            ok = false;
            }

            What is the point of catching an exception if you then throw it away?

            Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

            M E 2 Replies Last reply
            0
            • L Lost User

              catch (OleDbException)
              {
              ok = false;
              }

              What is the point of catching an exception if you then throw it away?

              Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

              M Offline
              M Offline
              MemberDotNetting
              wrote on last edited by
              #6

              In fact I have another idea that will start with this idea, in fact I have a WPF application, following the click on the button I want to select the name of the database via an open file dialog and display the name source in textebox, the method returns a message box to display the exception, but I used the bool type because my class is linked to a library and I can't use the message box

              D 1 Reply Last reply
              0
              • M MemberDotNetting

                In fact I have another idea that will start with this idea, in fact I have a WPF application, following the click on the button I want to select the name of the database via an open file dialog and display the name source in textebox, the method returns a message box to display the exception, but I used the bool type because my class is linked to a library and I can't use the message box

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                So have you heard of Debug.WriteLine()?? Wihtout the exception messages, it's pretty much impossible to tell you what's wrong with any accuracy.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                1 Reply Last reply
                0
                • M MemberDotNetting

                  sorry?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  No where did you say what errors you was getting or any exceptions. "It does not work" is not at all helpful in any way in describing your problem. How do you know it doesn't work? Did you get an error? Did you get an exception? Did your harddrive melt? We can't see your database or read your mind.

                  Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

                  1 Reply Last reply
                  0
                  • L Lost User

                    catch (OleDbException)
                    {
                    ok = false;
                    }

                    What is the point of catching an exception if you then throw it away?

                    Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

                    E Offline
                    E Offline
                    Enhakiel
                    wrote on last edited by
                    #9

                    if you are under win7 x64 make sure target solution's plateform is x86

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups