views:

162

answers:

3

I have an access database with 3 tables.

  • People
  • Gifts
  • PeopleGifts

Using VS 2008, what is the quickest way to get a page up and running which allows me to run queries against these tables and do basic inserts.

I want to have comboboxs bound to fields in the table so a user can click on a person and click on a gift and they click "Add".

A: 

try using an oleDBDataAdapter and a formview

YonahW
+2  A: 

The quickest way? Iron Speed

Mitch Wheat
A: 
public interface IOleDbDataGateway
{
    void ExecuteNonQuery(string sql, params object[] args);
    object ExecuteScalar(string sql, params object[] args);
    DataTable FillDataTable(string sql, params object[] args);
}

public class OleDbDataGateway : IOleDbDataGateway
{
    private readonly string connectionString;

    public OleDbDataGateway(string connectionString)
    {
        this.connectionString = connectionString;
    }

    public void ExecuteNonQuery(string sql, params object[] args)
    {
        if (args != null)
        {
            sql = string.Format(sql, args);
        }
        var connection = new OleDbConnection(connectionString);
        var command = new OleDbCommand(sql, connection);
        connection.Open();
        try
        {
            command.ExecuteNonQuery();
        }
        finally
        {
            connection.Close();
        }
    }

    public object ExecuteScalar(string sql, params object[] args)
    {
        if (args != null)
        {
            sql = string.Format(sql, args);
        }
        var connection = new OleDbConnection(connectionString);
        var command = new OleDbCommand(sql, connection);
        connection.Open();
        try
        {
            return command.ExecuteScalar();
        }
        finally
        {
            connection.Close();
        }
    }

    public DataTable FillDataTable(string sql, params object[] args)
    {
        if (args != null)
        {
            sql = string.Format(sql, args);
        }
        var connection = new OleDbConnection(connectionString);
        var adapter = new OleDbDataAdapter(sql, connection);
        var table = new DataTable();
        connection.Open();
        try
        {
            adapter.Fill(table);
        }
        finally
        {
            connection.Close();
        }
        return table;
    }
}
Tim Scott