I'm confused about how to link my app to an Access database - there seems to be a number of approaches.

I can add in my database via the Data Sources tab. Fine if I want to bind controls and view/edit data. But is this the best approach for queries that return an answer that is a different shape to the original table?

Alternatively I can connect to the database directly (connection string, etc) and run sql queries.

What are advantages/disadvantages of each approach? In terms of flexibility, is the second approach best? Also, does the second approach require the database to be added via the Data Sources tab?

Many thanks

>What are advantages/disadvantages of each approach?

That's true that there are number of approaches to perform database operations but all these approaches are came form ADO.NET core API to ease database I/O.

my personal preferenceis connection strings. (adodb, mysqlclient, and so on i dont use access databases)

i feel that it gives me more freedom.. but i never really gave the data sources tab much of a chance to begin with.

i want source code to connect my front end to microsoftaccess database after filling a form written in asp.net.vb

string connectionString = "datasource=localhost;username=xxx;password=xxx;database=xxx";
MySqlConnection mySqlConnection = new MySqlConnection(connectionString);

string selectString =
"SELECT username, password " +
"FROM forum_members " +
"WHERE username = '" + frmUsername.Text + "' AND password = '" + frmPassword.Text + "'";

MySqlCommand mySqlCommand = new MySqlCommand(selectString, mySqlConnection);
mySqlConnection.Open();
String strResult = String.Empty;
strResult = (String)mySqlCommand.ExecuteScalar();
mySqlConnection.Close();

if (strResult.Length == 0)
{
  Label1.Text = "INCORRECT USER/PASS!"
  //could redirect to register page
} else {
  Label1.Text = "YOU ARE LOGGED IN!";
  //set loggin in sessions variables
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.