This line:
- string conString =@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=c:\billing.mdb";
Declares a string variable called "conString" that contains information on for connecting to a database. This type of string is referred to as a
Connection String.
The next line declares and creates a new instance of a
OleDbConnection. The OleDbConnection is used to connect to a database. It requires the Connection String in order to know how to connect to the database.
-
OleDbConnection conn = new OleDbConnection(conString);
The next line opens the connection to the database.
The next lines create a new instance of a
DataSet. A DataSet is a collection of
DataTables. These are fill with information retrieved from the database using a
DataAdapter.
-
-
DataSet ds = new DataSet();
-
OleDbDataAdapter adapter =
-
new OleDbDataAdapter("Select * from product where id=" + id, conn);
-
adapter.Fill(ds);
After executing the DataAdapter's Fill method, the DataSet is filled with DataTables that are populated with data retrieved from the database. In this case the SQL command executed is very simple and only 1 table is involved...therefore the DataSet will only contain 1 DataTable.
The following line closes the connection to the database because you're done working with the database (you've retrieved the data you need to work with)
In the following code, you are retrieving the 1 DataTable within the DataSet that was created for you by the DataAdpter.
Then you are looping through each row/record in that DataTable and retrieving the data stored in the "count" field/cell.
For some reason you're converting this into a .NET Integer type and are storing this into a variable called "data". I don't know why you're doing this...the data variable will continue to be replaced while looping....
-
DataTable dt = ds.Tables[0];
-
foreach (DataRow dr in dt.Rows)
-
{
-
data = Convert.ToInt32(dr["count"]);
-
}
So, the result of this code is that "data" is filled with the "count" information for the last row/record in the data table retrieved from the database.
Whenever you don't understand what a control is in a piece of code you should refer to the
MSDN Library. This library contains documentation, articles, walk-throughs on all of the .NET controls and programming concepts. I have added links to each control and concept that was used in the code you posted. In the future please use the Search function of the MSDN Library to research a control before asking about it.
-Frinny