|
 |
aspx_beginners thread: Beginning ASP.NET 1.0 with c# (Example on pg. 519)
Message #1 by "Stephen Ho" <stephen_lman_ho@h...> on Mon, 16 Sep 2002 06:16:38
|
|
This example uses the Northwind.mdb file from MS access. When I try to
run the example, I get the follow error:
Operation must use an updateable query.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Operation must use
an updateable query.
Source Error:
Line 76:
Line 77: // Update the data store
Line 78: objAdapter.Update(objDataSet, "Employees");
Line 79:
Line 80: // Refresh the data in the DataReader and bind it to a new
grid
--------------------------------------------------------------------------
Here's the code for that example:
<%@ debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script Language="c#" runat="server">
void Page_Load(object sender, EventArgs e)
{
string strConnection, strSQL;
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = null;
OleDbDataAdapter objAdapter = null;
// Set the connection and query details
strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=C:\BegASPNET\Ch13\Northwind.mdb";
strSQL = "SELECT EmployeeID, FirstName, LastName FROM Employees;";
// Open the connection and set the command
objConnection = new OleDbConnection(strConnection);
objAdapter = new OleDbDataAdapter(strSQL, objConnection);
// Fill the dataset with the data
objAdapter.Fill(objDataSet, "Employees");
// Bind the data grid to the data
dgNameList1.DataSource = objDataSet.Tables["Employees"].DefaultView;
dgNameList1.DataBind();
// Add a new row to the table
DataTable objTable = null;
DataRow objnewRow = null;
objTable = objDataSet.Tables["Employees"];
objnewRow = objTable.NewRow();
objnewRow["FirstName"] = "Norman";
objnewRow["LastName"] = "Blake";
objTable.Rows.Add(objnewRow);
// Add another new row. We'll be deleting the one above later.
// We can't delete existing rows from the database because of
// referential integrity (every employee also has Orders)
objnewRow = objTable.NewRow();
objnewRow["FirstName"] = "Kasey";
objnewRow["LastName"] = "Chambers";
objTable.Rows.Add(objnewRow);
// Bind the data grid to the new data
dgNameList2.DataSource = objTable.DefaultView;
dgNameList2.DataBind();
// Edit an existing row in the table
DataRow objRow = null;
// The Rows collection is 0 indexed, so this changes the fourth row
objRow = objTable.Rows[3];
objRow["FirstName"] = "John";
objRow["LastName"] = "Hartford";
// Bind the data grid to the new data
dgNameList3.DataSource = objTable.DefaultView;
dgNameList3.DataBind();
// Delete a row from the table
// The Rows collection is 0 indexed, so this removes the second row
from
// the end
objTable.Rows[objTable.Rows.Count - 2].Delete();
// Bind the data grid to the new data
dgNameList4.DataSource = objTable.DefaultView;
dgNameList4.DataBind();
// Generate the update commands
OleDbCommandBuilder objBuilder = null;
objBuilder = new OleDbCommandBuilder(objAdapter);
objAdapter.UpdateCommand = objBuilder.GetUpdateCommand();
objAdapter.InsertCommand = objBuilder.GetInsertCommand();
objAdapter.DeleteCommand = objBuilder.GetDeleteCommand();
// Update the data store
objAdapter.Update(objDataSet, "Employees");
// Refresh the data in the DataReader and bind it to a new grid
// to prove that the data store has been updated
strSQL = "SELECT EmployeeID, FirstName, LastName FROM Employees";
objConnection.Open();
OleDbCommand objCmd = new OleDbCommand(strSQL, objConnection);
dgUpd.DataSource = objCmd.ExecuteReader
(CommandBehavior.CloseConnection);
dgUpd.DataBind();
}
</script>
<html>
<body>
<table width="100%">
<tr>
<td>Original Data</td>
<td>Data with new Row</td>
<td>Data with edited Row</td>
<td>Data with deleted Row</td>
</tr>
<tr>
<td valign="top"><asp:DataGrid id="dgNameList1" runat="server" /></td>
<td valign="top"><asp:DataGrid id="dgNameList2" runat="server" /></td>
<td valign="top"><asp:DataGrid id="dgNameList3" runat="server" /></td>
<td valign="top"><asp:DataGrid id="dgNameList4" runat="server" /></td>
</tr>
</table>
<hr />
Data fetched from database after the update:<br/>
<asp:DataGrid id="dgUpd" runat="server"/>
</body>
</html>
--------------------------------------------------------------------------
Can someone tell me what's wrong here !
Thanks,
Stephen
Message #2 by miss ruby <unix_box@y...> on Mon, 16 Sep 2002 01:39:36 -0700 (PDT)
|
|
emm... same error with me.. please refer to
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=50852
to solve the error..
--- Stephen Ho <stephen_lman_ho@h...> wrote:
> This example uses the Northwind.mdb file from MS
> access. When I try to
> run the example, I get the follow error:
>
> Operation must use an updateable query.
>
> Description: An unhandled exception occurred during
> the execution of the
> current web request. Please review the stack trace
> for more information
> about the error and where it originated in the code.
>
>
> Exception Details: System.Data.OleDb.OleDbException:
> Operation must use
> an updateable query.
>
> Source Error:
>
>
> Line 76:
> Line 77: // Update the data store
> Line 78: objAdapter.Update(objDataSet,
> "Employees");
> Line 79:
> Line 80: // Refresh the data in the DataReader
> and bind it to a new
> grid
>
>
--------------------------------------------------------------------------
> Here's the code for that example:
>
> <%@ debug="true" %>
> <%@ Import Namespace="System.Data" %>
> <%@ Import Namespace="System.Data.OleDb" %>
> <script Language="c#" runat="server">
> void Page_Load(object sender, EventArgs e)
> {
> string strConnection, strSQL;
> DataSet objDataSet = new DataSet();
> OleDbConnection objConnection = null;
> OleDbDataAdapter objAdapter = null;
>
> // Set the connection and query details
> strConnection
> "Provider=Microsoft.Jet.OleDb.4.0;";
> strConnection += @"Data
> Source=C:\BegASPNET\Ch13\Northwind.mdb";
> strSQL = "SELECT EmployeeID, FirstName, LastName
> FROM Employees;";
>
> // Open the connection and set the command
> objConnection = new
> OleDbConnection(strConnection);
> objAdapter = new OleDbDataAdapter(strSQL,
> objConnection);
>
> // Fill the dataset with the data
> objAdapter.Fill(objDataSet, "Employees");
>
> // Bind the data grid to the data
> dgNameList1.DataSource
> objDataSet.Tables["Employees"].DefaultView;
> dgNameList1.DataBind();
>
> // Add a new row to the table
> DataTable objTable = null;
> DataRow objnewRow = null;
> objTable = objDataSet.Tables["Employees"];
> objnewRow = objTable.NewRow();
> objnewRow["FirstName"] = "Norman";
> objnewRow["LastName"] = "Blake";
> objTable.Rows.Add(objnewRow);
>
> // Add another new row. We'll be deleting the
> one above later.
> // We can't delete existing rows from the
> database because of
> // referential integrity (every employee also
> has Orders)
> objnewRow = objTable.NewRow();
> objnewRow["FirstName"] = "Kasey";
> objnewRow["LastName"] = "Chambers";
> objTable.Rows.Add(objnewRow);
>
> // Bind the data grid to the new data
> dgNameList2.DataSource = objTable.DefaultView;
> dgNameList2.DataBind();
>
> // Edit an existing row in the table
> DataRow objRow = null;
>
> // The Rows collection is 0 indexed, so this
> changes the fourth row
> objRow = objTable.Rows[3];
> objRow["FirstName"] = "John";
> objRow["LastName"] = "Hartford";
>
> // Bind the data grid to the new data
> dgNameList3.DataSource = objTable.DefaultView;
> dgNameList3.DataBind();
>
> // Delete a row from the table
> // The Rows collection is 0 indexed, so this
> removes the second row
> from
> // the end
> objTable.Rows[objTable.Rows.Count - 2].Delete();
>
> // Bind the data grid to the new data
> dgNameList4.DataSource = objTable.DefaultView;
> dgNameList4.DataBind();
>
> // Generate the update commands
> OleDbCommandBuilder objBuilder = null;
> objBuilder = new
> OleDbCommandBuilder(objAdapter);
> objAdapter.UpdateCommand
> objBuilder.GetUpdateCommand();
> objAdapter.InsertCommand
> objBuilder.GetInsertCommand();
> objAdapter.DeleteCommand
> objBuilder.GetDeleteCommand();
>
> // Update the data store
> objAdapter.Update(objDataSet, "Employees");
>
> // Refresh the data in the DataReader and bind
> it to a new grid
> // to prove that the data store has been updated
> strSQL = "SELECT EmployeeID, FirstName, LastName
> FROM Employees";
> objConnection.Open();
> OleDbCommand objCmd = new OleDbCommand(strSQL,
> objConnection);
> dgUpd.DataSource = objCmd.ExecuteReader
> (CommandBehavior.CloseConnection);
> dgUpd.DataBind();
> }
> </script>
>
> <html>
> <body>
> <table width="100%">
> <tr>
> <td>Original Data</td>
> <td>Data with new Row</td>
> <td>Data with edited Row</td>
> <td>Data with deleted Row</td>
> </tr>
> <tr>
> <td valign="top"><asp:DataGrid id="dgNameList1"
> runat="server" /></td>
> <td valign="top"><asp:DataGrid id="dgNameList2"
> runat="server" /></td>
> <td valign="top"><asp:DataGrid id="dgNameList3"
> runat="server" /></td>
> <td valign="top"><asp:DataGrid id="dgNameList4"
> runat="server" /></td>
> </tr>
> </table>
> <hr />
> Data fetched from database after the update:<br/>
> <asp:DataGrid id="dgUpd" runat="server"/>
> </body>
> </html>
>
>
--------------------------------------------------------------------------
> Can someone tell me what's wrong here !
>
> Thanks,
> Stephen
> ---
> Beginning ASP.NET Databases using VB.NET
> http://www.wrox.com/ACON11.asp?ISBN=1861006195
>
> Beginning ASP.NET Databases using C#
> http://www.wrox.com/ACON11.asp?ISBN=1861007418
>
> These books look at how we can create data-centric
> ASP.NET
> applications. Requiring some basic knowledge of
> ASP.NET,
> Access and SQL the authors guide you through the
> process
> of connecting and consuming information in a variety
> of
> ways. They are packed full of excellent illustrative
> code
> examples, demonstrating important fundamental
> principles.
=====
miss ruby
malaysia
__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com
Message #3 by "Stephen Ho" <stephen_lman_ho@h...> on Tue, 17 Sep 2002 08:32:49
|
|
> Thanks for the help !
emm... same error with me.. please refer to
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=50852
to solve the error..
--- Stephen Ho <stephen_lman_ho@h...> wrote:
> This example uses the Northwind.mdb file from MS
> access. When I try to
> run the example, I get the follow error:
>
> Operation must use an updateable query.
>
> Description: An unhandled exception occurred during
> the execution of the
> current web request. Please review the stack trace
> for more information
> about the error and where it originated in the code.
>
>
> Exception Details: System.Data.OleDb.OleDbException:
> Operation must use
> an updateable query.
>
> Source Error:
>
>
> Line 76:
> Line 77: // Update the data store
> Line 78: objAdapter.Update(objDataSet,
> "Employees");
> Line 79:
> Line 80: // Refresh the data in the DataReader
> and bind it to a new
> grid
>
>
--------------------------------------------------------------------------
> Here's the code for that example:
>
> <%@ debug="true" %>
> <%@ Import Namespace="System.Data" %>
> <%@ Import Namespace="System.Data.OleDb" %>
> <script Language="c#" runat="server">
> void Page_Load(object sender, EventArgs e)
> {
> string strConnection, strSQL;
> DataSet objDataSet = new DataSet();
> OleDbConnection objConnection = null;
> OleDbDataAdapter objAdapter = null;
>
> // Set the connection and query details
> strConnection
> "Provider=Microsoft.Jet.OleDb.4.0;";
> strConnection += @"Data
> Source=C:\BegASPNET\Ch13\Northwind.mdb";
> strSQL = "SELECT EmployeeID, FirstName, LastName
> FROM Employees;";
>
> // Open the connection and set the command
> objConnection = new
> OleDbConnection(strConnection);
> objAdapter = new OleDbDataAdapter(strSQL,
> objConnection);
>
> // Fill the dataset with the data
> objAdapter.Fill(objDataSet, "Employees");
>
> // Bind the data grid to the data
> dgNameList1.DataSource
> objDataSet.Tables["Employees"].DefaultView;
> dgNameList1.DataBind();
>
> // Add a new row to the table
> DataTable objTable = null;
> DataRow objnewRow = null;
> objTable = objDataSet.Tables["Employees"];
> objnewRow = objTable.NewRow();
> objnewRow["FirstName"] = "Norman";
> objnewRow["LastName"] = "Blake";
> objTable.Rows.Add(objnewRow);
>
> // Add another new row. We'll be deleting the
> one above later.
> // We can't delete existing rows from the
> database because of
> // referential integrity (every employee also
> has Orders)
> objnewRow = objTable.NewRow();
> objnewRow["FirstName"] = "Kasey";
> objnewRow["LastName"] = "Chambers";
> objTable.Rows.Add(objnewRow);
>
> // Bind the data grid to the new data
> dgNameList2.DataSource = objTable.DefaultView;
> dgNameList2.DataBind();
>
> // Edit an existing row in the table
> DataRow objRow = null;
>
> // The Rows collection is 0 indexed, so this
> changes the fourth row
> objRow = objTable.Rows[3];
> objRow["FirstName"] = "John";
> objRow["LastName"] = "Hartford";
>
> // Bind the data grid to the new data
> dgNameList3.DataSource = objTable.DefaultView;
> dgNameList3.DataBind();
>
> // Delete a row from the table
> // The Rows collection is 0 indexed, so this
> removes the second row
> from
> // the end
> objTable.Rows[objTable.Rows.Count - 2].Delete();
>
> // Bind the data grid to the new data
> dgNameList4.DataSource = objTable.DefaultView;
> dgNameList4.DataBind();
>
> // Generate the update commands
> OleDbCommandBuilder objBuilder = null;
> objBuilder = new
> OleDbCommandBuilder(objAdapter);
> objAdapter.UpdateCommand
> objBuilder.GetUpdateCommand();
> objAdapter.InsertCommand
> objBuilder.GetInsertCommand();
> objAdapter.DeleteCommand
> objBuilder.GetDeleteCommand();
>
> // Update the data store
> objAdapter.Update(objDataSet, "Employees");
>
> // Refresh the data in the DataReader and bind
> it to a new grid
> // to prove that the data store has been updated
> strSQL = "SELECT EmployeeID, FirstName, LastName
> FROM Employees";
> objConnection.Open();
> OleDbCommand objCmd = new OleDbCommand(strSQL,
> objConnection);
> dgUpd.DataSource = objCmd.ExecuteReader
> (CommandBehavior.CloseConnection);
> dgUpd.DataBind();
> }
> </script>
>
> <html>
> <body>
> <table width="100%">
> <tr>
> <td>Original Data</td>
> <td>Data with new Row</td>
> <td>Data with edited Row</td>
> <td>Data with deleted Row</td>
> </tr>
> <tr>
> <td valign="top"><asp:DataGrid id="dgNameList1"
> runat="server" /></td>
> <td valign="top"><asp:DataGrid id="dgNameList2"
> runat="server" /></td>
> <td valign="top"><asp:DataGrid id="dgNameList3"
> runat="server" /></td>
> <td valign="top"><asp:DataGrid id="dgNameList4"
> runat="server" /></td>
> </tr>
> </table>
> <hr />
> Data fetched from database after the update:<br/>
> <asp:DataGrid id="dgUpd" runat="server"/>
> </body>
> </html>
>
>
--------------------------------------------------------------------------
> Can someone tell me what's wrong here !
>
> Thanks,
> Stephen
> ---
> Beginning ASP.NET Databases using VB.NET
> http://www.wrox.com/ACON11.asp?ISBN=1861006195
>
> Beginning ASP.NET Databases using C#
> http://www.wrox.com/ACON11.asp?ISBN=1861007418
>
> These books look at how we can create data-centric
> ASP.NET
> applications. Requiring some basic knowledge of
> ASP.NET,
> Access and SQL the authors guide you through the
> process
> of connecting and consuming information in a variety
> of
> ways. They are packed full of excellent illustrative
> code
> examples, demonstrating important fundamental
> principles.
=====
miss ruby
malaysia
__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com
|
|
 |