An exception of type System.IndexOutOfRangeException was thrown.?

An exception of type System.IndexOutOfRangeException was thrown.?

Post by Steve Schofiel » Thu, 14 Dec 2000 07:13:08



Anyone seen this error.  I was deploying a page to be demo'd on aspfree and
got this error.  sometimes it works some times it doesn't.  I tried moving
the Page_Onload event above all the user controls and still the same error
happens.  This passes the variables to a stored procedure and returns the
identity value.




%>

Src="/includes/bottompage.ascx" %>
<script language="VB" runat="server">
 Dim MyConnection As SQLConnection

    Sub Page_Load(Sender As Object, E As EventArgs)

 MyConnection = New
SQLConnection("server=remoteserver;uid=sa;pwd=;database=mydb")

' Dim Config as HashTable
' Config = Context.GetConfig("appsettings")
' MyConnection = New SQLConnection(Config("MyConn"))

    End Sub

    Sub b1_OnClick(Sender As Object, E As EventArgs)

        Dim MyCommand = New SQLCommand("sp_ReturnIdentity", MyConnection)

 MyCommand.CommandType = CommandType.StoredProcedure
        Dim workParam As SQLParameter = Nothing


SQLDataType.VarChar, 50))


SQLDataType.VarChar, 50))


SQLDataType.VarChar, 50))

        workParam = MyCommand.Parameters.Add(New

        workParam.Direction = ParameterDirection.Output

 MyCommand.ActiveConnection.Open()

 'Execute the command
 MyCommand.Execute()

 'Place the identity value into a local variable
 'To be used in other places
 dim strID as string

' response.write(strID)

 'close connection string
        MyCommand.ActiveConnection.Close()
      End Sub

</script>

<Top:TopStuff runat="server"/>

<h3><font face="Verdana">Inserting a Row of Data and Returning the Identity
Value with ASP.NET</font></h3>
<table>
<td>
<a href="/aspdotnet/returnidentity.aspx">Return to the article</a>

<h2>Your ID: is <font color="#FF0000"></font></h2>

<form method="post" name="form1" runat="server">
      <strong>First Name</strong><br>
      <input type="text" size="40" name="FName"><br>
      <strong>Last Name</strong><br>
      <input type="text" size="40" name="LName"><br>
      <strong>FavoriteColor</strong><br>
      <input type="text" size="40" name="FavColor"><br>
      <p>
      <input type="submit" OnServerClick="b1_OnClick" value="Add Record"
runat="server">
      </font>
</form>
</td>
</table>

<Bottom:BottomStuff runat="server"/>

--
* -----------------------------------------*
* Steve Schofield

*
* Webmaster
* http://www.aspfree.com
* http://www.abc2xml.com
* http://www.thinclientzone.com
* -----------------------------------------
*** "Your ASP Technology Super-WebSite" ***

 
 
 

An exception of type System.IndexOutOfRangeException was thrown.?

Post by Steve Schofiel » Thu, 14 Dec 2000 07:27:26


An update.  I removed the user controls and stuff and it appears to work.  I
don't do anything in the user controls besides some HTML formatting.   Any
clues??

--
* -----------------------------------------*
* Steve Schofield

*
* Webmaster
* http://www.aspfree.com
* http://www.abc2xml.com
* http://www.thinclientzone.com
* -----------------------------------------
*** "Your ASP Technology Super-WebSite" ***

> Anyone seen this error.  I was deploying a page to be demo'd on aspfree
and
> got this error.  sometimes it works some times it doesn't.  I tried moving
> the Page_Onload event above all the user controls and still the same error
> happens.  This passes the variables to a stored procedure and returns the
> identity value.





Src="/includes/toppage.ascx"
> %>

> Src="/includes/bottompage.ascx" %>
> <script language="VB" runat="server">
>  Dim MyConnection As SQLConnection

>     Sub Page_Load(Sender As Object, E As EventArgs)

>  MyConnection = New
> SQLConnection("server=remoteserver;uid=sa;pwd=;database=mydb")

> ' Dim Config as HashTable
> ' Config = Context.GetConfig("appsettings")
> ' MyConnection = New SQLConnection(Config("MyConn"))

>     End Sub

>     Sub b1_OnClick(Sender As Object, E As EventArgs)

>         Dim MyCommand = New SQLCommand("sp_ReturnIdentity", MyConnection)

>  MyCommand.CommandType = CommandType.StoredProcedure
>         Dim workParam As SQLParameter = Nothing


> SQLDataType.VarChar, 50))


> SQLDataType.VarChar, 50))


> SQLDataType.VarChar, 50))

>         workParam = MyCommand.Parameters.Add(New

>         workParam.Direction = ParameterDirection.Output

>  MyCommand.ActiveConnection.Open()

>  'Execute the command
>  MyCommand.Execute()

>  'Place the identity value into a local variable
>  'To be used in other places
>  dim strID as string

> ' response.write(strID)

>  'close connection string
>         MyCommand.ActiveConnection.Close()
>       End Sub

> </script>

> <Top:TopStuff runat="server"/>

> <h3><font face="Verdana">Inserting a Row of Data and Returning the
Identity
> Value with ASP.NET</font></h3>
> <table>
> <td>
> <a href="/aspdotnet/returnidentity.aspx">Return to the article</a>

> <h2>Your ID: is <font color="#FF0000"></font></h2>

> <form method="post" name="form1" runat="server">
>       <strong>First Name</strong><br>
>       <input type="text" size="40" name="FName"><br>
>       <strong>Last Name</strong><br>
>       <input type="text" size="40" name="LName"><br>
>       <strong>FavoriteColor</strong><br>
>       <input type="text" size="40" name="FavColor"><br>
>       <p>
>       <input type="submit" OnServerClick="b1_OnClick" value="Add Record"
> runat="server">
>       </font>
> </form>
> </td>
> </table>

> <Bottom:BottomStuff runat="server"/>

> --
> * -----------------------------------------*
> * Steve Schofield

> *
> * Webmaster
> * http://www.aspfree.com
> * http://www.abc2xml.com
> * http://www.thinclientzone.com
> * -----------------------------------------
> *** "Your ASP Technology Super-WebSite" ***


 
 
 

An exception of type System.IndexOutOfRangeException was thrown.?

Post by Tom Jone » Thu, 14 Dec 2000 08:09:26


Steve, I can't really say... At first it was working, then it didn't (threw
the System.IndexOutOfRangeException).

Now, I replaced:

myCommand.Execute

with

myCommand.ExecuteNonQuery()

It has yet to throw the error..

Btw, ExecuteNonQuery() is the new method for commands / sp that don't return
a result set...

Tom Jones


> An update.  I removed the user controls and stuff and it appears to work.
I
> don't do anything in the user controls besides some HTML formatting.   Any
> clues??

> --
> * -----------------------------------------*
> * Steve Schofield

> *
> * Webmaster
> * http://www.aspfree.com
> * http://www.abc2xml.com
> * http://www.thinclientzone.com
> * -----------------------------------------
> *** "Your ASP Technology Super-WebSite" ***


> > Anyone seen this error.  I was deploying a page to be demo'd on aspfree
> and
> > got this error.  sometimes it works some times it doesn't.  I tried
moving
> > the Page_Onload event above all the user controls and still the same
error
> > happens.  This passes the variables to a stored procedure and returns
the
> > identity value.




> Src="/includes/toppage.ascx"
> > %>

> > Src="/includes/bottompage.ascx" %>
> > <script language="VB" runat="server">
> >  Dim MyConnection As SQLConnection

> >     Sub Page_Load(Sender As Object, E As EventArgs)

> >  MyConnection = New
> > SQLConnection("server=remoteserver;uid=sa;pwd=;database=mydb")

> > ' Dim Config as HashTable
> > ' Config = Context.GetConfig("appsettings")
> > ' MyConnection = New SQLConnection(Config("MyConn"))

> >     End Sub

> >     Sub b1_OnClick(Sender As Object, E As EventArgs)

> >         Dim MyCommand = New SQLCommand("sp_ReturnIdentity",
MyConnection)

> >  MyCommand.CommandType = CommandType.StoredProcedure
> >         Dim workParam As SQLParameter = Nothing


> > SQLDataType.VarChar, 50))


> > SQLDataType.VarChar, 50))


> > SQLDataType.VarChar, 50))


request.form("Favcolor")

- Show quoted text -

> >         workParam = MyCommand.Parameters.Add(New

> >         workParam.Direction = ParameterDirection.Output

> >  MyCommand.ActiveConnection.Open()

> >  'Execute the command
> >  MyCommand.Execute()

> >  'Place the identity value into a local variable
> >  'To be used in other places
> >  dim strID as string

> > ' response.write(strID)

> >  'close connection string
> >         MyCommand.ActiveConnection.Close()
> >       End Sub

> > </script>

> > <Top:TopStuff runat="server"/>

> > <h3><font face="Verdana">Inserting a Row of Data and Returning the
> Identity
> > Value with ASP.NET</font></h3>
> > <table>
> > <td>
> > <a href="/aspdotnet/returnidentity.aspx">Return to the article</a>

> > <h2>Your ID: is <font color="#FF0000"></font></h2>

> > <form method="post" name="form1" runat="server">
> >       <strong>First Name</strong><br>
> >       <input type="text" size="40" name="FName"><br>
> >       <strong>Last Name</strong><br>
> >       <input type="text" size="40" name="LName"><br>
> >       <strong>FavoriteColor</strong><br>
> >       <input type="text" size="40" name="FavColor"><br>
> >       <p>
> >       <input type="submit" OnServerClick="b1_OnClick" value="Add Record"
> > runat="server">
> >       </font>
> > </form>
> > </td>
> > </table>

> > <Bottom:BottomStuff runat="server"/>

> > --
> > * -----------------------------------------*
> > * Steve Schofield

> > *
> > * Webmaster
> > * http://www.aspfree.com
> > * http://www.abc2xml.com
> > * http://www.thinclientzone.com
> > * -----------------------------------------
> > *** "Your ASP Technology Super-WebSite" ***