(C#) Ch09 errata EditingData.aspx: not working
(C#) Ch09 errata EditingData.aspx: not working
Hey all,
I'm working through the Beginning ASP.NET 1.1 vis C# 03 book, and things are peachy until Chapter 9, Try It Out code called "EditingData.aspx." Then troubles. There is errata on the site, yes with changes for the end of the script: the only p.295 errata listed at <http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764557084,descCd-view_errata.html>.
Updating the code with the errata does nothing but change the error message. Here's the final script (errata noted):
void Page_Load(Object sender, EventArgs e) {
string connectionString;
string queryString;
DataSet data = new DataSet();
OleDbConnection dbConnection;
OleDbDataAdapter dataAdapter;
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=C:\\BegASPNet11\\data\\Northwind.mdb";
queryString = "SELECT FirstName, LastName FROM Employees";
dbConnection = new OleDbConnection(connectionString);
dataAdapter = new OleDbDataAdapter(queryString, dbConnection);
dataAdapter.Fill(data, "Employees");
DataGrid1.DataSource = data;
DataGrid1.DataBind();
// ---------------------------------------------------------
// Marker 1
DataTable table;
DataRow newRow;
table = data.Tables["Employees"];
newRow = table.NewRow();
newRow["FirstName"] = "Norman";
newRow["LastName"] = "Blake";
table.Rows.Add(newRow);
// bind the second grid to the new data
DataGrid2.DataSource = table;
DataGrid2.DataBind();
// ---------------------------------------------------------
// Marker 2
DataRow[] selectedRows;
//----- ERRATA START -----
// find the row to change
selectedRows = table.Select("FirstName='Margaret' AND LastName='Peacock'");
if (selectedRows.Length > 0)
{
selectedRows(0).item("FirstName") = "John";
selectedRows(0).item("LastName") = "Hartford";
}
// bind the data grid to the new data
DataGrid3.DataSource = table;
DataGrid3.DataBind();
//----- END ERRATA -----
// ---------------------------------------------------------
// Marker 3
// The Rows collection is 0 indexed, therefore
// this deletes the sixth row
table.Rows[5].Delete();
// bind the fourth grid to the new data
DataGrid4.DataSource = table;
DataGrid4.DataBind();
}
And here's the brief compiler error message:
Compiler Error Message: CS0118: 'selectedRows' denotes a 'variable' where a 'method' was expected
Source Error:
Line 47: if (selectedRows.Length > 0)
Line 48: {
Line 49: selectedRows(0).item("FirstName") = "John";
Line 50: selectedRows(0).item("LastName") = "Hartford";
Line 51: }
This gotta be me, right? I inserted the fixed code incorrectly? I know that there is a proviso before the code, stating that since the code should alter the databse, the dbase will have to be reset. But since I've never gotten the code to work, I figured that shouldn't be an issue (plus, I can't make the reset code work either).
Thanks in advance for anyone's time
Matt
|