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