Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2006, 06:34 AM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to ECPcenter Send a message via MSN to ECPcenter
Default Index was outside the bounds of the array

-------------------------------------------------------------
The system "Exception Details:"Index was outside the bounds of the array"" -----------How wrong? who can tell me?

<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    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;

         // find the row to change
         selectedRows = table.Select("FirstName='Margaret' AND LastName='Peacock'");
         selectedRows[0]["FirstName"] = "John";
         selectedRows[0]["LastName"] = "Hartford";

         // bind the third grid to this new data
         DataGrid3.DataSource = table;
         DataGrid3.DataBind();
         // ---------------------------------------------------------
         // 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();
       }

</script>
<html>
<head>
</head>
<body>
    <table width="100%">
        <tbody>
            <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="DataGrid1" runat="server"></asp:DataGrid>
                </td>
                <td valign="top">
                    <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
                </td>
                <td valign="top">
                    <asp:DataGrid id="DataGrid3" runat="server"></asp:DataGrid>
                </td>
                <td valign="top">
                    <asp:DataGrid id="DataGrid4" runat="server"></asp:DataGrid>
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>
-------------------------------------------------------------

 
Old September 14th, 2006, 06:51 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This is error is hard to figure out becacuse i dont actually know what data is being returned to your dataset; Check to make sure all of the data you are trying to pull from the dataset exists and is in the dimension you expect it in.

"The one language all programmers understand is profanity."
 
Old September 14th, 2006, 08:01 PM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to ECPcenter Send a message via MSN to ECPcenter
Default

Thanks

 
Old July 5th, 2008, 04:55 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The error could be in the section Marker 2.
The Select filter statement might not have returned any row and you are trying to access it by row index.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Bounds mjhoagland Classic ASP Basics 9 September 28th, 2006 09:01 AM
Index was outside the bounds of the array dba123 Reporting Services 0 March 6th, 2006 11:25 AM
index outside bounds of array error? barmanvarn BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 February 17th, 2005 03:25 PM
System.Index out of Bounds chiraagb ADO.NET 3 June 10th, 2004 12:39 PM
Array index rajanikrishna Beginning PHP 1 December 3rd, 2003 02:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.