Connecting to MS Access Database From .NET 2.0

For some reason, I couldn't find a good example online. Remembered I had done this successfully with PC Sitter Web. Here's the code that returns an array list:

Code:
try
         {
            string strSQL = "SELECT * FROM Albums";
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +                                             Server.MapPath(
                System.Configuration.ConfigurationManager.ConnectionStrings
                ["AccessPhotoGalConnectionString"].ToString());

            DataTable dataTable = new DataTable();
            OleDbDataAdapter lDbConn =
                new OleDbDataAdapter(strSQL, ConnectionString);
            DbConnAdapter = lDbConn;

            DbConnAdapter.Fill(dataTable);

            //loop thru database tables
            foreach (DataRow dr in dataTable.Rows)
            {                
                arrPhotos.Add(dr.ItemArray);
                counter++;
            }          
        }
        catch (Exception ex)
        {          
            UIManager.LogError(ex);
            throw ex;
        }

        return arrPhotos;

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name (required)

 Email (will not be published) (required)

Your comment is 0 characters limited to 3000 characters.