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. Open a database--Please disregard the question-i found the answer--Sorry for the trouble

Open a database--Please disregard the question-i found the answer--Sorry for the trouble

Scheduled Pinned Locked Moved C#
helpcsharpdatabasegraphicsquestion
2 Posts 2 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.
  • N Offline
    N Offline
    new2pgrmg
    wrote on last edited by
    #1

    Hi, I am trying to open a MS Access database from C# code. I want the MSAccess database to open up on a button click. Am able to create a connection to the database but am unable to open the database. i want the database to be open on a button click event so that i can open a table. Atached below is my code.Any help is welcome :). using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using ADOX; using System.Data.OleDb; using System.Runtime.InteropServices; namespace DatabaseCreation { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtdatabaseName.Text; OleDbConnection myAccessConn = null; try { myAccessConn = new OleDbConnection(strAccessConn); myAccessConn.Open(); MessageBox.Show("Database connection is successfully Opened"); } catch (Exception ex) { MessageBox.Show("Error: Failed to create a database connection. \n{0}", ex.Message); } if (myAccessConn.State == ConnectionState.Open) { myAccessConn.Close(); MessageBox.Show("Database is successfully Closed"); } } } }

    modified on Wednesday, April 23, 2008 5:40 AM

    T 1 Reply Last reply
    0
    • N new2pgrmg

      Hi, I am trying to open a MS Access database from C# code. I want the MSAccess database to open up on a button click. Am able to create a connection to the database but am unable to open the database. i want the database to be open on a button click event so that i can open a table. Atached below is my code.Any help is welcome :). using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using ADOX; using System.Data.OleDb; using System.Runtime.InteropServices; namespace DatabaseCreation { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtdatabaseName.Text; OleDbConnection myAccessConn = null; try { myAccessConn = new OleDbConnection(strAccessConn); myAccessConn.Open(); MessageBox.Show("Database connection is successfully Opened"); } catch (Exception ex) { MessageBox.Show("Error: Failed to create a database connection. \n{0}", ex.Message); } if (myAccessConn.State == ConnectionState.Open) { myAccessConn.Close(); MessageBox.Show("Database is successfully Closed"); } } } }

      modified on Wednesday, April 23, 2008 5:40 AM

      T Offline
      T Offline
      Thomas Stockwell
      wrote on last edited by
      #2

      So you know in the future. If no one has responded to your question you have the ability to delete the message using the 'Delete' button in the lower right hand corner of the message.

      Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

      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