OK with 1.1, System.IndexOutOfRangeException with 2

A

acb

Hi,

I have an aspx page that works well with Framework 1.1 and crashes with
Framework 2. What follows is the error page and the source code.

--- error page

Server Error in '/' Application.
--------------------------------------------------------------------------------

Index was outside the bounds of the array.
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.IndexOutOfRangeException: Index was outside
the bounds of the array.

Source Error:


Line 22: DataSet dataset = new DataSet();
Line 23: dataset.Clear();
Line 24: adapter.Fill(dataset,"StatCountry");
Line 25:
Line 26: DataView dvw = dataset.Tables["StatCountry"].DefaultView;


Source File:
c:\Inetpub\wwwroot\VISUALASPNET\Ch06\ASPDataGrid_cache.aspx Line: 24


Stack Trace:


[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Data.ProviderBase.DbBuffer.ReadTime(Int32 offset) +1034856
System.Data.Odbc.CNativeBuffer.MarshalToManaged(Int32 offset, SQL_C
sqlctype, Int32 cb) +588
System.Data.Odbc.OdbcDataReader.GetBoundColumnValue(Int32 i) +667
System.Data.Odbc.OdbcDataReader.internalGetValue(Int32 i) +85
System.Data.Odbc.OdbcDataReader.GetValues() +28
System.Data.Odbc.OdbcDataReader.Read() +284
System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping
mapping) +156
System.Data.Common.DataAdapter.FillFromReader(DataSet dataset,
DataTable datatable, String srcTable, DataReaderContainer dataReader,
Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn,
Object parentChapterValue) +157
System.Data.Common.DataAdapter.Fill(DataSet dataSet, String
srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
+172
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior) +175
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable) +83
ASP.ASPDataGrid_cache_aspx.Page_Load(Object Sender, EventArgs e) in
c:\Inetpub\wwwroot\VISUALASPNET\Ch06\ASPDataGrid_cache.aspx:24
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e) +36
System.Web.UI.Control.OnLoad(EventArgs e) +102
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1064




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50215.44;
ASP.NET Version:2.0.50215.44


----- source code

<%@ Page Language="C#" Debug="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>

<html>
<head>
<script Language="C#" runat="server">
// DATABASE CONNECTION


void Page_Load (Object Sender, EventArgs e)
{
if (!IsPostBack)
{
string connection = "DSN=Cache";
string query = "SELECT * FROM StatCountry";

OdbcConnection conn = new OdbcConnection(connection);
OdbcDataAdapter adapter = new OdbcDataAdapter();
adapter.SelectCommand = new OdbcCommand(query, conn);

DataSet dataset = new DataSet();
adapter.Fill(dataset,"StatCountry");

DataView dvw = dataset.Tables["StatCountry"].DefaultView;

MyDataGrid.DataSource = dvw;
MyDataGrid.DataBind();
}
}
</script>
</head>

<body>

<asp:datagrid id="MyDataGrid" runat="server" />

</body>
</html>


--------- end code

Thank you

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top