Access connections from Visual Studio

Import classes

using System.Data;
using System.Configuration;
using System.Data.OleDb;

set up your app config

<add name="AccessConnection" 
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\location\accessdb.mdb;
		Persist Security Info=False;;"/>
  public DataTable accessquery()

            OleDbCommand command = new OleDbCommand();
            command.CommandType = CommandType.Text;
            //command.Parameters.AddWithValue("@reportdata", document);
            command.CommandText = "Select * from tablename";
            DataTable dt = new DataTable();
            dt = accessconnection(command);
            return dt;
 private DataTable accessconnection(OleDbCommand command)
            string OLEDBConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["AccessConnection"].ConnectionString;
            OleDbConnection cns = new OleDbConnection(OLEDBConnectionString);
            DataSet CustomersDataSet = new DataSet();
            OleDbDataAdapter dp = default(OleDbDataAdapter);
            command.Connection = cns;
            dp = new OleDbDataAdapter(command);
            if (CustomersDataSet.Tables.Count > 0)
                return CustomersDataSet.Tables[0];
            DataTable dt = new DataTable();
            return dt;

Comments are closed.

Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /homepages/35/d428352912/htdocs/WilliamMendoza/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048