Results 1 to 5 of 5

Thread: [RESOLVED] help connecting to DB

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Resolved [RESOLVED] help connecting to DB

    Hi all,


    Im not sure where im going wrong but here is my source code

    its a single access2003 DB with one table called WinAudi2

    Code:
    BindingSource CA_bindingsource = new BindingSource();
            
    
            private void button1_Click(object sender, EventArgs e)
            {
            string MyString;    
            System.Data.Odbc.OdbcConnection cn;
            System.Data.Odbc.OdbcCommand cmd;
            MyString = "Select * from WinAudi2"; 
            cn = new System.Data.Odbc.OdbcConnection(@"Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\Sweep.mdb;Uid=Admin;Pwd=;");
            cmd = new System.Data.Odbc.OdbcCommand(MyString, cn);
    
            try
            {
                cn.Open();
    
    
                CA_bindingsource.DataSource = cmd;
                dataGridView1.DataSource = CA_bindingsource;
                MessageBox.Show("Connected");
            }
    
            catch (Exception ex)
            {
                //MessageBox.Show("Error with CSV backup" + Environment.NewLine + ex.Message);
                Console.WriteLine(ex.ToString());
                MessageBox.Show("Problem" + Environment.NewLine + ex.Message);
            }
    
    
            finally
            {
                cn.Close();
            }

    and when i go to run the code i get this



    Am i not structuring something right?
    Last edited by Crash893; Feb 7th, 2007 at 07:33 PM.

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