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

Edited by JohnDove: n/a

7 Years
Discussion Span
Last Post by vagheladev

>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.

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);
String strResult = String.Empty;
strResult = (String)mySqlCommand.ExecuteScalar();

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

Edited by __avd: Added [code] tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.