step1. Import two namespace "System.Data" and "System.Data.OleDb" or "System.Data.SqlConnection"
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.OleDb (or System.Data.SqlConnection)" %>
step2. Creates a connection. Define two variables with the type of string, named ConnectionString and CommandText. To hold the connection string and the text for the command to run. In the ConnectionString always use salsh character(\\) instand of the slash character(\), or use the @ symbol before part of the string.
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=[Driver]:\......\*.mdb";
System.Data.IDbConnection dbConnection =
new System.Data.OleDb.OleDbConnection(connectionString);
step3. Creates a command. first,define a SQL string:
string queryString = "...The SQL Command...";
Now define the command object:
System.Data.IDbCommand dbCommand = new System.Data.OleDbCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConnection;
step4. Creates a data adapter.
System.Data.IDbDataAdapter dataAdapter =
new System.Data.OleDb.OleDbDataAdapter();
The data adapter is the link between the page and the data, it provides not only data fetching, but also data modification. There are four objects we could use: SelectCommand(Fetches data), UpdataCommand, InsertCommand, DeleteCommand.
dataAdapter.[object] = dbCommand;
step5. Fetch the data. Use the Fill() method of the data adapter, passing in the DataSet. This opens the database connection, runs the command, place the data into the DataSet,and then closes the database connection.
System.Data.DataSet = new System.Data.DataSet();
dataAdapter.Fill(dataSet);
return dataSet;