The second column has an index of 2, and so on. Here is an example that gets the values of different fields: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.OleDb; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { using (OleDbConnection Connect = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("exercise.mdb"))) { string strItems = "SELECT * FROM Customers WHERE AccountNumber = '427006';"; OleDbCommand cmdCustomers = new OleDbCommand(strItems, Connect); Connect.Open(); OleDbDataReader rdr = cmdCustomers.ExecuteReader(); while (rdr.Read()) { txtAccountNumber.Text = rdr[0].ToString(); txtFirstName.Text = rdr[1].ToString(); txtLastName.Text = rdr[2].ToString(); } } } } To retrieve the actual data stored in a column, you may need to know the type of information the column is holding so you can read it accurately. Before sending the data, you must convert the value read to the appropriate (and probably exact) format. Here are examples: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.OleDb; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { using (OleDbConnection Connect = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("exercise.mdb"))) { string strItems = "SELECT * FROM Customers WHERE AccountNumber = '427006';"; OleDbCommand cmdCustomers = new OleDbCommand(strItems, Connect); Connect.Open(); OleDbDataReader rdr = cmdCustomers.ExecuteReader(); while (rdr.Read()) { txtAccountNumber.Text = rdr.GetString(0); txtFirstName.Text = rdr.GetString(1); txtLastName.Text = rdr.GetString(2); } } } } |
|