Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: You've been there before...


Message #1 by "Tim Farrell" <timothy.farrell@c...> on Thu, 30 May 2002 16:36:48
This query represents a situation all of us have been presented with in 
our current and past days of learning programming languages when you go 
out and get a book and attempt to learn from documentation and example.  
However, when you get to an example that you would like to implement and 
work your way though the code, you find out that you can't get it to work.
That's where I'm at right now.  I have spent a couple of days trying to 
figure out how to rectify the error to no avail.  And so I come to you.  
The Best and the Brightest of the ASP world!:)

I am attempting to learn how to implement the edit control in the 
datagrid.  I am acquiring the knowledge to do this trought a book 
called "Programming Data-Driven Web Applications with ASP.Net".  I have 
copied their code to the letter replacing connection string info and 
table, column names where necessary.  I am getting the following error:

StringBuilder is not defined.

When I look at the code, I believe the error to be true.  Here is the code:

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient


Public Class A1 : Inherits Page
    Protected DGEmployee As DataGrid

    Private sSQLCon As String 
= "server=ntphoenix;database=employee;uid=sa;pwd=;"

    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)


        If Not Page.IsPostBack Then
            Bind()
        End If
    End Sub


    Private Sub Bind()
        Dim SQLCon As New SqlConnection(sSQLCon)
        Dim SqlCmd As New StringBuilder()
        SqlCmd.Append("Select * FROM Employee")
        Dim sda As New SqlDataAdapter(SqlCmd.ToString(), SQLCon)
        Dim ds As New DataSet()
        sda.Fill(ds, "employee")
        DGEmployee.DataSource = ds.Tables("Employee").DefaultView
        DGEmployee.DataBind()

    End Sub

    Public Sub DGEmployee_Edit(ByVal sender As Object, ByVal e As 
DataGridCommandEventArgs)

        DGEmployee.EditItemIndex = e.Item.ItemIndex
        Bind()

    End Sub

    Public Sub DGEmployee_Cancel(ByVal sender As Object, ByVal e As 
DataGridCommandEventArgs)

        DGEmployee.EditItemIndex = -1
        Bind()

    End Sub

    Public Sub DGEmployee_Update(ByVal sender As Object, ByVal e As 
DataGridCommandEventArgs)

        Dim sInitials, sLastName, sFirstName, sUID, sPWD, sSecurity, sID 
As String
        sInitials = CType(e.Item.Cells(1).Controls(0), TextBox).Text
        sLastName = CType(e.Item.Cells(2).Controls(0), TextBox).Text
        sFirstName = CType(e.Item.Cells(3).Controls(0), TextBox).Text
        sUID = CType(e.Item.Cells(4).Controls(0), TextBox).Text
        sPWD = CType(e.Item.Cells(5).Controls(0), TextBox).Text
        sSecurity = CType(e.Item.Cells(6).Controls(0), TextBox).Text
        sID = cType(e.Item.Cells(7).Text

        Dim sSqlCmd As New StringBuilder()
        sSqlCmd.Append("Update Employee ")
        sSqlCmd.Append("Set Initials = @Initials,")
        sSqlCmd.Append("LastName = @LastName,")
        sSqlCmd.Append("FirstName = @FirstName,")
        sSqlCmd.Append("UID = @UID,")
        sSqlCmd.Append("PWD = @PWD,")
        sSqlCmd.Append("Security = @Security,")
        sSqlCmd.Append("WHERE ID = @ID,")

        Dim SqlCon As New SqlConnection(sSQLCon)
        Dim SqlCmd As New SqlCommand(sSqlCmd.ToString(), SqlCon)
        SqlCmd.Parameters.Add(New SqlParameter("@Initials", 
SqlDbType.NVarChar, 8))
        SqlCmd.Parameters("@Initials").Value = sInitials
        SqlCmd.Parameters.Add(New SqlParameter("@LastName", 
SqlDbType.NVarChar, 50))
        SqlCmd.Parameters("@LastName").Value = sLastName
        SqlCmd.Parameters.Add(New SqlParameter("@FirstName", 
SqlDbType.NVarChar, 50))
        SqlCmd.Parameters("@FirstName").Value = sFirstName
        SqlCmd.Parameters.Add(New SqlParameter("@UID", SqlDbType.NVarChar, 
10))
        SqlCmd.Parameters("@UID").Value = sUID
        SqlCmd.Parameters.Add(New SqlParameter("@PWD", SqlDbType.NVarChar, 
10))
        SqlCmd.Parameters("@PWD").Value = sPWD
        SqlCmd.Parameters.Add(New SqlParameter("@Security", SqlDbType.Int, 
3))
        SqlCmd.Parameters("@Security").Value = sSecurity
        SqlCmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int, 3))
        SqlCmd.Parameters("@ID").Value = sID

        SqlCon.Open()
        SqlCmd.ExecuteNonQuery()
        SqlCon.Close()

        DGEmployee.EditItemIndex = -1
        Bind()

    End Sub

End Class



Can anyone help me out of this one?  If it is an error on the part of the 
authors I would like to inform them as well.  Also, what is important to 
note is that this code is contained within the *.aspx.vb code-behind page.

Thank you all very much for any help you may be able to provide.

Sincerely,

Tim

Message #2 by "Minh T. Nguyen" <nguyentriminh@y...> on Thu, 30 May 2002 08:35:14 -0700
Tim,

	Without telling us exactly one which line you have encountered
this error, I can only guess, and my best shot is that you (or I guess
better: the book) did not import the System.Text namespace that is
required for the StringBuilder class.

Hope this helps,
Minh.

PS: The majority of the .NET books were all written in beta state, as
such, you'll find a lot of problems in a lot of books.

-----Original Message-----
From: Tim Farrell [mailto:timothy.farrell@c...] 
Sent: Thursday, May 30, 2002 4:37 PM
To: aspx_beginners
Subject: [aspx_beginners] You've been there before...


This query represents a situation all of us have been presented with in 
our current and past days of learning programming languages when you go 
out and get a book and attempt to learn from documentation and example.

However, when you get to an example that you would like to implement and

work your way though the code, you find out that you can't get it to
work.
That's where I'm at right now.  I have spent a couple of days trying to 
figure out how to rectify the error to no avail.  And so I come to you.

The Best and the Brightest of the ASP world!:)

I am attempting to learn how to implement the edit control in the 
datagrid.  I am acquiring the knowledge to do this trought a book 
called "Programming Data-Driven Web Applications with ASP.Net".  I have 
copied their code to the letter replacing connection string info and 
table, column names where necessary.  I am getting the following error:

StringBuilder is not defined.

When I look at the code, I believe the error to be true.  Here is the
code:

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient


Public Class A1 : Inherits Page
    Protected DGEmployee As DataGrid

    Private sSQLCon As String 
= "server=ntphoenix;database=employee;uid=sa;pwd=;"

    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)


        If Not Page.IsPostBack Then
            Bind()
        End If
    End Sub


    Private Sub Bind()
        Dim SQLCon As New SqlConnection(sSQLCon)
        Dim SqlCmd As New StringBuilder()
        SqlCmd.Append("Select * FROM Employee")
        Dim sda As New SqlDataAdapter(SqlCmd.ToString(), SQLCon)
        Dim ds As New DataSet()
        sda.Fill(ds, "employee")
        DGEmployee.DataSource = ds.Tables("Employee").DefaultView
        DGEmployee.DataBind()

    End Sub

    Public Sub DGEmployee_Edit(ByVal sender As Object, ByVal e As 
DataGridCommandEventArgs)

        DGEmployee.EditItemIndex = e.Item.ItemIndex
        Bind()

    End Sub

    Public Sub DGEmployee_Cancel(ByVal sender As Object, ByVal e As 
DataGridCommandEventArgs)

        DGEmployee.EditItemIndex = -1
        Bind()

    End Sub

    Public Sub DGEmployee_Update(ByVal sender As Object, ByVal e As 
DataGridCommandEventArgs)

        Dim sInitials, sLastName, sFirstName, sUID, sPWD, sSecurity, sID

As String
        sInitials = CType(e.Item.Cells(1).Controls(0), TextBox).Text
        sLastName = CType(e.Item.Cells(2).Controls(0), TextBox).Text
        sFirstName = CType(e.Item.Cells(3).Controls(0), TextBox).Text
        sUID = CType(e.Item.Cells(4).Controls(0), TextBox).Text
        sPWD = CType(e.Item.Cells(5).Controls(0), TextBox).Text
        sSecurity = CType(e.Item.Cells(6).Controls(0), TextBox).Text
        sID = cType(e.Item.Cells(7).Text

        Dim sSqlCmd As New StringBuilder()
        sSqlCmd.Append("Update Employee ")
        sSqlCmd.Append("Set Initials = @Initials,")
        sSqlCmd.Append("LastName = @LastName,")
        sSqlCmd.Append("FirstName = @FirstName,")
        sSqlCmd.Append("UID = @UID,")
        sSqlCmd.Append("PWD = @PWD,")
        sSqlCmd.Append("Security = @Security,")
        sSqlCmd.Append("WHERE ID = @ID,")

        Dim SqlCon As New SqlConnection(sSQLCon)
        Dim SqlCmd As New SqlCommand(sSqlCmd.ToString(), SqlCon)
        SqlCmd.Parameters.Add(New SqlParameter("@Initials", 
SqlDbType.NVarChar, 8))
        SqlCmd.Parameters("@Initials").Value = sInitials
        SqlCmd.Parameters.Add(New SqlParameter("@LastName", 
SqlDbType.NVarChar, 50))
        SqlCmd.Parameters("@LastName").Value = sLastName
        SqlCmd.Parameters.Add(New SqlParameter("@FirstName", 
SqlDbType.NVarChar, 50))
        SqlCmd.Parameters("@FirstName").Value = sFirstName
        SqlCmd.Parameters.Add(New SqlParameter("@UID",
SqlDbType.NVarChar, 
10))
        SqlCmd.Parameters("@UID").Value = sUID
        SqlCmd.Parameters.Add(New SqlParameter("@PWD",
SqlDbType.NVarChar, 
10))
        SqlCmd.Parameters("@PWD").Value = sPWD
        SqlCmd.Parameters.Add(New SqlParameter("@Security",
SqlDbType.Int, 
3))
        SqlCmd.Parameters("@Security").Value = sSecurity
        SqlCmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int, 3))
        SqlCmd.Parameters("@ID").Value = sID

        SqlCon.Open()
        SqlCmd.ExecuteNonQuery()
        SqlCon.Close()

        DGEmployee.EditItemIndex = -1
        Bind()

    End Sub

End Class



Can anyone help me out of this one?  If it is an error on the part of
the 
authors I would like to inform them as well.  Also, what is important to

note is that this code is contained within the *.aspx.vb code-behind
page.

Thank you all very much for any help you may be able to provide.

Sincerely,

Tim


Message #3 by "Farrell, Timothy" <Timothy.Farrell@C...> on Thu, 30 May 2002 13:09:55 -0400
Minh,

Sorry about the ommition, it was this line :
Dim SqlCmd As New StringBuilder()

I surely didn't mean that I was out to slam the authors.  To a large extent
I wouldn't be where I am in developing without their dedication and time in
writing the books.  You perspective is eye opening and I appreciate your
thoughts.

As you indicated, the Imports System.Text namespace was not included in the
documentation.  Once I incorporated your thoughts into the script, the error
was gone.

Thank you so much.


However, now I am getting an error when I press the update link.  Here is
the error:

System.ArgumentOutOfRangeException: Specified argument was out of the range
of valid values. Parameter name: index.

Once again the code:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient


Public Class A1 : Inherits Page
    Protected DGEmployee As DataGrid

    Private sSQLCon As String 
"server=ntphoenix;database=plan;uid=sa;pwd=;"

    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)


        If Not Page.IsPostBack Then
            Bind()
        End If
    End Sub

    Protected Sub PageIndexChanged_OnClick(ByVal Sender As Object, ByVal E
As DataGridPageChangedEventArgs)
        DGEmployee.CurrentPageIndex = E.NewPageIndex
        Bind()
    End Sub


    Private Sub Bind()
        Dim SQLCon As New SqlConnection(sSQLCon)
        Dim SqlCmd As New StringBuilder()
        SqlCmd.Append("Select * FROM Employee")
        Dim sda As New SqlDataAdapter(SqlCmd.ToString(), SQLCon)
        Dim ds As New DataSet()
        sda.Fill(ds, "employee")
        DGEmployee.DataSource = ds.Tables("Employee").DefaultView
        DGEmployee.DataBind()

    End Sub

    Public Sub DGEmployee_Edit(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

        DGEmployee.EditItemIndex = e.Item.ItemIndex
        Bind()

    End Sub

    Public Sub DGEmployee_Cancel(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

        DGEmployee.EditItemIndex = -1
        Bind()

    End Sub

    Public Sub DGEmployee_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

        Dim sInitials, sLastName, sFirstName, sUID, sPWD, sSecurity, sID As
String
        sInitials = CType(e.Item.Cells(1).Controls(0), TextBox).Text
        sLastName = CType(e.Item.Cells(2).Controls(0), TextBox).Text
        sFirstName = CType(e.Item.Cells(3).Controls(0), TextBox).Text
        sUID = CType(e.Item.Cells(4).Controls(0), TextBox).Text
        sPWD = CType(e.Item.Cells(5).Controls(0), TextBox).Text
        sSecurity = CType(e.Item.Cells(6).Controls(0), TextBox).Text
        sID = e.Item.Cells(7).Text

        Dim sSqlCmd As New StringBuilder()
        sSqlCmd.Append("Update Employee ")
        sSqlCmd.Append("Set Initials = @Initials,")
        sSqlCmd.Append("LastName = @LastName,")
        sSqlCmd.Append("FirstName = @FirstName,")
        sSqlCmd.Append("UID = @UID,")
        sSqlCmd.Append("PWD = @PWD,")
        sSqlCmd.Append("Security = @Security,")
        sSqlCmd.Append("WHERE ID = @ID,")

        Dim SqlCon As New SqlConnection(sSQLCon)
        Dim SqlCmd As New SqlCommand(sSqlCmd.ToString(), SqlCon)
        SqlCmd.Parameters.Add(New SqlParameter("@Initials",
SqlDbType.NVarChar, 8))
        SqlCmd.Parameters("@Initials").Value = sInitials
        SqlCmd.Parameters.Add(New SqlParameter("@LastName",
SqlDbType.NVarChar, 50))
        SqlCmd.Parameters("@LastName").Value = sLastName
        SqlCmd.Parameters.Add(New SqlParameter("@FirstName",
SqlDbType.NVarChar, 50))
        SqlCmd.Parameters("@FirstName").Value = sFirstName
        SqlCmd.Parameters.Add(New SqlParameter("@UID", SqlDbType.NVarChar,
10))
        SqlCmd.Parameters("@UID").Value = sUID
        SqlCmd.Parameters.Add(New SqlParameter("@PWD", SqlDbType.NVarChar,
10))
        SqlCmd.Parameters("@PWD").Value = sPWD
        SqlCmd.Parameters.Add(New SqlParameter("@Security", SqlDbType.Int,
3))
        SqlCmd.Parameters("@Security").Value = sSecurity
        SqlCmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int, 3))
        SqlCmd.Parameters("@ID").Value = sID

        SqlCon.Open()
        SqlCmd.ExecuteNonQuery()
        SqlCon.Close()

        DGEmployee.EditItemIndex = -1
        Bind()

    End Sub

End Class


Sincerely,

Tim




The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it. 

Message #4 by "Minh T. Nguyen" <nguyentriminh@y...> on Thu, 30 May 2002 10:30:42 -0700
Tim,

	Without telling us exactly one which line you have encountered
this error, I wouldn't know what to do, as I can't find a variable named
"index" anywhere in your code. Well, whatever it is, I recommend putting
a break point at that line and then look at the value of "index" and see
where you want to set that value. I can only guess that it must be in
the "DGEmployee.EditItemIndex = -1" line, but that looks correct to me,
to be honest.
	Someone else knows more about this?

Minh.

-----Original Message-----
From: Farrell, Timothy [mailto:Timothy.Farrell@C...] 
Sent: Thursday, May 30, 2002 10:10 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: You've been there before...


Minh,

Sorry about the ommition, it was this line :
Dim SqlCmd As New StringBuilder()

I surely didn't mean that I was out to slam the authors.  To a large
extent
I wouldn't be where I am in developing without their dedication and time
in
writing the books.  You perspective is eye opening and I appreciate your
thoughts.

As you indicated, the Imports System.Text namespace was not included in
the
documentation.  Once I incorporated your thoughts into the script, the
error
was gone.

Thank you so much.


However, now I am getting an error when I press the update link.  Here
is
the error:

System.ArgumentOutOfRangeException: Specified argument was out of the
range
of valid values. Parameter name: index.

Once again the code:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient


Public Class A1 : Inherits Page
    Protected DGEmployee As DataGrid

    Private sSQLCon As String 
"server=ntphoenix;database=plan;uid=sa;pwd=;"

    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)


        If Not Page.IsPostBack Then
            Bind()
        End If
    End Sub

    Protected Sub PageIndexChanged_OnClick(ByVal Sender As Object, ByVal
E
As DataGridPageChangedEventArgs)
        DGEmployee.CurrentPageIndex = E.NewPageIndex
        Bind()
    End Sub


    Private Sub Bind()
        Dim SQLCon As New SqlConnection(sSQLCon)
        Dim SqlCmd As New StringBuilder()
        SqlCmd.Append("Select * FROM Employee")
        Dim sda As New SqlDataAdapter(SqlCmd.ToString(), SQLCon)
        Dim ds As New DataSet()
        sda.Fill(ds, "employee")
        DGEmployee.DataSource = ds.Tables("Employee").DefaultView
        DGEmployee.DataBind()

    End Sub

    Public Sub DGEmployee_Edit(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

        DGEmployee.EditItemIndex = e.Item.ItemIndex
        Bind()

    End Sub

    Public Sub DGEmployee_Cancel(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

        DGEmployee.EditItemIndex = -1
        Bind()

    End Sub

    Public Sub DGEmployee_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

        Dim sInitials, sLastName, sFirstName, sUID, sPWD, sSecurity, sID
As
String
        sInitials = CType(e.Item.Cells(1).Controls(0), TextBox).Text
        sLastName = CType(e.Item.Cells(2).Controls(0), TextBox).Text
        sFirstName = CType(e.Item.Cells(3).Controls(0), TextBox).Text
        sUID = CType(e.Item.Cells(4).Controls(0), TextBox).Text
        sPWD = CType(e.Item.Cells(5).Controls(0), TextBox).Text
        sSecurity = CType(e.Item.Cells(6).Controls(0), TextBox).Text
        sID = e.Item.Cells(7).Text

        Dim sSqlCmd As New StringBuilder()
        sSqlCmd.Append("Update Employee ")
        sSqlCmd.Append("Set Initials = @Initials,")
        sSqlCmd.Append("LastName = @LastName,")
        sSqlCmd.Append("FirstName = @FirstName,")
        sSqlCmd.Append("UID = @UID,")
        sSqlCmd.Append("PWD = @PWD,")
        sSqlCmd.Append("Security = @Security,")
        sSqlCmd.Append("WHERE ID = @ID,")

        Dim SqlCon As New SqlConnection(sSQLCon)
        Dim SqlCmd As New SqlCommand(sSqlCmd.ToString(), SqlCon)
        SqlCmd.Parameters.Add(New SqlParameter("@Initials",
SqlDbType.NVarChar, 8))
        SqlCmd.Parameters("@Initials").Value = sInitials
        SqlCmd.Parameters.Add(New SqlParameter("@LastName",
SqlDbType.NVarChar, 50))
        SqlCmd.Parameters("@LastName").Value = sLastName
        SqlCmd.Parameters.Add(New SqlParameter("@FirstName",
SqlDbType.NVarChar, 50))
        SqlCmd.Parameters("@FirstName").Value = sFirstName
        SqlCmd.Parameters.Add(New SqlParameter("@UID",
SqlDbType.NVarChar,
10))
        SqlCmd.Parameters("@UID").Value = sUID
        SqlCmd.Parameters.Add(New SqlParameter("@PWD",
SqlDbType.NVarChar,
10))
        SqlCmd.Parameters("@PWD").Value = sPWD
        SqlCmd.Parameters.Add(New SqlParameter("@Security",
SqlDbType.Int,
3))
        SqlCmd.Parameters("@Security").Value = sSecurity
        SqlCmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int, 3))
        SqlCmd.Parameters("@ID").Value = sID

        SqlCon.Open()
        SqlCmd.ExecuteNonQuery()
        SqlCon.Close()

        DGEmployee.EditItemIndex = -1
        Bind()

    End Sub

End Class


Sincerely,

Tim




The contents of this e-mail are intended for the named addressee only.
It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or
disclose
it to anyone else. If you received it in error please notify us
immediately
and then destroy it. 



Message #5 by "Farrell, Timothy" <Timothy.Farrell@C...> on Thu, 30 May 2002 13:46:06 -0400
Minh,

Thanks again for your time, I unfortunately do not know which line is
causing the error since the error message also did not indicate a line #.
What I did was to search for any line that contained the item "Index" and
all seemed to be correct.  I do not have a parameter named index either.

The only reason I'm not sure that the line you specified below is the
problem is because the function works when cancel is clicked.  Which takes
you back to the initial datagrid with record unchanged.

It's a bazar world we program in... :)

-----Original Message-----
From: Minh T. Nguyen [mailto:nguyentriminh@y...]
Sent: Thursday, May 30, 2002 1:31 PM
To: aspx_beginners
Subject: [aspx_beginners] RE: You've been there before...


Tim,

	Without telling us exactly one which line you have encountered
this error, I wouldn't know what to do, as I can't find a variable named
"index" anywhere in your code. Well, whatever it is, I recommend putting
a break point at that line and then look at the value of "index" and see
where you want to set that value. I can only guess that it must be in
the "DGEmployee.EditItemIndex = -1" line, but that looks correct to me,
to be honest.
	Someone else knows more about this?

Minh.



The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it. 

Message #6 by "Minh T. Nguyen" <nguyentriminh@y...> on Thu, 30 May 2002 10:52:45 -0700
Tim,

	Very interesting. How can you not have a line number when
getting the exception? Have you compiled the project in debug mode? How
do you get the exception? In VS.NET or as a web page on your IE?

Good luck,
Minh.

-----Original Message-----
From: Farrell, Timothy [mailto:Timothy.Farrell@C...] 
Sent: Thursday, May 30, 2002 10:46 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: You've been there before...


Minh,

Thanks again for your time, I unfortunately do not know which line is
causing the error since the error message also did not indicate a line
#.
What I did was to search for any line that contained the item "Index"
and
all seemed to be correct.  I do not have a parameter named index either.

The only reason I'm not sure that the line you specified below is the
problem is because the function works when cancel is clicked.  Which
takes
you back to the initial datagrid with record unchanged.

It's a bazar world we program in... :)

Message #7 by "Farrell, Timothy" <Timothy.Farrell@C...> on Thu, 30 May 2002 14:02:20 -0400
Minh,

I am receiving the error in IE.  In VS.Net I get no indication that there is
a problem.  Ususally I get a line number from the error messaging via IE
however, not this time.

What I do get is detail stack info if that will help:

[ArgumentOutOfRangeException: Specified argument was out of the range of
valid values.
Parameter name: index]
   System.Web.UI.ControlCollection.get_Item(Int32 index) +58
   A1.DGEmployee_Update(Object sender, DataGridCommandEventArgs e) +58
 
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e) +109
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs
e) +748
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +100
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +120
 
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument) +115
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
   System.Web.UI.Page.ProcessRequestMain() +1263

Thanks again for hanging in there.

Tim

-----Original Message-----
From: Minh T. Nguyen [mailto:nguyentriminh@y...]
Sent: Thursday, May 30, 2002 1:53 PM
To: aspx_beginners
Subject: [aspx_beginners] RE: You've been there before...


Tim,

	Very interesting. How can you not have a line number when
getting the exception? Have you compiled the project in debug mode? How
do you get the exception? In VS.NET or as a web page on your IE?

Good luck,
Minh.



The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it. 

Message #8 by "Minh T. Nguyen" <nguyentriminh@y...> on Thu, 30 May 2002 11:22:16 -0700
Tim,

	I am sorry. I can't think of what that would occur. Your error
occurs in this line:
	System.Web.UI.ControlCollection.get_Item(Int32 index) +58

	which seems to be an internal line (something that you didn't
write). That's why we can't find the index parameter. 

Here's what I suggest you do. Compile this in debug mode and debug it
with VS.NET by hitting F5. Then, set a break point at the very first
line of your Update event handler. See if that event handler is actually
getting fired. If not, then the event handler is not properly set up.
Fix it by going to the design view, click on the datagrid, click on the
event button in the properties window (the one with the Harry Potter
thunder, as I'd like to call it) and then click double-click on the
field text box next to Update. This will properly set up the event
handler.

	If the event handler does get fired, then, just simply step one
line at a time to see when you hit the exception. This way, we can
localize on which line in your code the exception gets internally
raised. You mentioned that VS.NET does not indicate any error. I am not
quite sure if I understand that, how can the website display the
exception but VS.NET does not detect it in debug mode?
	Try tracing it, by setting trace=on in your web.config file and
put a bunch of System.Diagnostics.Trace.WriteLine("I am here");
statements scattered through your code and while browsing your website,
take a look at http://localhost/YourWebApplication/trace.axd.

	At last, UI.ControlCollection.get_Item(Int32 index) seems to me
that the ASP.NET worker process is trying to find the DSEmployee control
by getting that particular item (this is a guess). Maybe we can help it
a little by instead of using "DSEmployee" we simply use "(DataGrid)
sender" since that should be the same object.

Hope this all helps somehow,
Minh.

-----Original Message-----
From: Farrell, Timothy [mailto:Timothy.Farrell@C...] 
Sent: Thursday, May 30, 2002 11:02 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: You've been there before...


Minh,

I am receiving the error in IE.  In VS.Net I get no indication that
there is
a problem.  Ususally I get a line number from the error messaging via IE
however, not this time.

What I do get is detail stack info if that will help:

[ArgumentOutOfRangeException: Specified argument was out of the range of
valid values.
Parameter name: index]
   System.Web.UI.ControlCollection.get_Item(Int32 index) +58
   A1.DGEmployee_Update(Object sender, DataGridCommandEventArgs e) +58
 
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventA
rgs
e) +109
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs
e) +748
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+26
   System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +100
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+26
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
+120
 
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler
.Rai
sePostBackEvent(String eventArgument) +115
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+138
   System.Web.UI.Page.ProcessRequestMain() +1263

Thanks again for hanging in there.

Tim

Message #9 by "Steven A Smith" <ssmith@a...> on Thu, 30 May 2002 15:22:35 -0400
This is the key reason why I think books should have their examples
*working* online, so that if you get stuck like this you can go and see the
actual working code and know for certain that the code really does work
(since so many book examples do not work).

<plug>Which is why ASP.NET By Example has all of its examples online at
http://aspauthors.com/aspnetbyexample/</plug>

Steve


Steven Smith, MCSE+Internet, Microsoft MVP: ASP.NET
ssmith@a...
President, ASPAlliance.com
http://aspalliance.com    The #1 ASP.NET Community
http://aspsmith.com        ASP.NET Training for ASP Developers

Learning ASP.NET?  Get My Book: ASP.NET By Example
http://amazon.com/exec/obidos/ASIN/0789725622/stevenatorasp/
----- Original Message -----
From: "Farrell, Timothy" <Timothy.Farrell@C...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Thursday, May 30, 2002 1:09 PM
Subject: [aspx_beginners] RE: You've been there before...


> Minh,
>
> Sorry about the ommition, it was this line :
> Dim SqlCmd As New StringBuilder()
>
> I surely didn't mean that I was out to slam the authors.  To a large
extent
> I wouldn't be where I am in developing without their dedication and time
in
> writing the books.  You perspective is eye opening and I appreciate your
> thoughts.
>
> As you indicated, the Imports System.Text namespace was not included in
the
> documentation.  Once I incorporated your thoughts into the script, the
error
> was gone.
>
> Thank you so much.
>
>
> However, now I am getting an error when I press the update link.  Here is
> the error:
>
> System.ArgumentOutOfRangeException: Specified argument was out of the
range
> of valid values. Parameter name: index.
>
> Once again the code:
> Imports System
> Imports System.Web
> Imports System.Web.UI
> Imports System.Web.UI.WebControls
> Imports System.Text
> Imports System.Data
> Imports System.Data.SqlClient
>
>
> Public Class A1 : Inherits Page
>     Protected DGEmployee As DataGrid
>
>     Private sSQLCon As String 
> "server=ntphoenix;database=plan;uid=sa;pwd=;"
>
>     Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
>
>
>         If Not Page.IsPostBack Then
>             Bind()
>         End If
>     End Sub
>
>     Protected Sub PageIndexChanged_OnClick(ByVal Sender As Object, ByVal E
> As DataGridPageChangedEventArgs)
>         DGEmployee.CurrentPageIndex = E.NewPageIndex
>         Bind()
>     End Sub
>
>
>     Private Sub Bind()
>         Dim SQLCon As New SqlConnection(sSQLCon)
>         Dim SqlCmd As New StringBuilder()
>         SqlCmd.Append("Select * FROM Employee")
>         Dim sda As New SqlDataAdapter(SqlCmd.ToString(), SQLCon)
>         Dim ds As New DataSet()
>         sda.Fill(ds, "employee")
>         DGEmployee.DataSource = ds.Tables("Employee").DefaultView
>         DGEmployee.DataBind()
>
>     End Sub
>
>     Public Sub DGEmployee_Edit(ByVal sender As Object, ByVal e As
> DataGridCommandEventArgs)
>
>         DGEmployee.EditItemIndex = e.Item.ItemIndex
>         Bind()
>
>     End Sub
>
>     Public Sub DGEmployee_Cancel(ByVal sender As Object, ByVal e As
> DataGridCommandEventArgs)
>
>         DGEmployee.EditItemIndex = -1
>         Bind()
>
>     End Sub
>
>     Public Sub DGEmployee_Update(ByVal sender As Object, ByVal e As
> DataGridCommandEventArgs)
>
>         Dim sInitials, sLastName, sFirstName, sUID, sPWD, sSecurity, sID
As
> String
>         sInitials = CType(e.Item.Cells(1).Controls(0), TextBox).Text
>         sLastName = CType(e.Item.Cells(2).Controls(0), TextBox).Text
>         sFirstName = CType(e.Item.Cells(3).Controls(0), TextBox).Text
>         sUID = CType(e.Item.Cells(4).Controls(0), TextBox).Text
>         sPWD = CType(e.Item.Cells(5).Controls(0), TextBox).Text
>         sSecurity = CType(e.Item.Cells(6).Controls(0), TextBox).Text
>         sID = e.Item.Cells(7).Text
>
>         Dim sSqlCmd As New StringBuilder()
>         sSqlCmd.Append("Update Employee ")
>         sSqlCmd.Append("Set Initials = @Initials,")
>         sSqlCmd.Append("LastName = @LastName,")
>         sSqlCmd.Append("FirstName = @FirstName,")
>         sSqlCmd.Append("UID = @UID,")
>         sSqlCmd.Append("PWD = @PWD,")
>         sSqlCmd.Append("Security = @Security,")
>         sSqlCmd.Append("WHERE ID = @ID,")
>
>         Dim SqlCon As New SqlConnection(sSQLCon)
>         Dim SqlCmd As New SqlCommand(sSqlCmd.ToString(), SqlCon)
>         SqlCmd.Parameters.Add(New SqlParameter("@Initials",
> SqlDbType.NVarChar, 8))
>         SqlCmd.Parameters("@Initials").Value = sInitials
>         SqlCmd.Parameters.Add(New SqlParameter("@LastName",
> SqlDbType.NVarChar, 50))
>         SqlCmd.Parameters("@LastName").Value = sLastName
>         SqlCmd.Parameters.Add(New SqlParameter("@FirstName",
> SqlDbType.NVarChar, 50))
>         SqlCmd.Parameters("@FirstName").Value = sFirstName
>         SqlCmd.Parameters.Add(New SqlParameter("@UID", SqlDbType.NVarChar,
> 10))
>         SqlCmd.Parameters("@UID").Value = sUID
>         SqlCmd.Parameters.Add(New SqlParameter("@PWD", SqlDbType.NVarChar,
> 10))
>         SqlCmd.Parameters("@PWD").Value = sPWD
>         SqlCmd.Parameters.Add(New SqlParameter("@Security", SqlDbType.Int,
> 3))
>         SqlCmd.Parameters("@Security").Value = sSecurity
>         SqlCmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int, 3))
>         SqlCmd.Parameters("@ID").Value = sID
>
>         SqlCon.Open()
>         SqlCmd.ExecuteNonQuery()
>         SqlCon.Close()
>
>         DGEmployee.EditItemIndex = -1
>         Bind()
>
>     End Sub
>
> End Class
>
>
> Sincerely,
>
> Tim
>
>
>
>
> The contents of this e-mail are intended for the named addressee only. It
> contains information that may be confidential. Unless you are the named
> addressee or an authorized designee, you may not copy or use it, or
disclose
> it to anyone else. If you received it in error please notify us
immediately
> and then destroy it.
>
>
>

Message #10 by "Farrell, Timothy" <Timothy.Farrell@C...> on Thu, 30 May 2002 15:27:53 -0400
My point as well.  And as I am sure you are aware, the book I am using does
not have a website or a point of contact for issues such as this.  The
authors are no where to be found.

At the very least, they should have to clearly mark which version of VS they
were coding for so that you wouldn't have to throw $39 away like that.  I am
really disappointed.

-----Original Message-----
From: Steven A Smith [mailto:ssmith@a...]
Sent: Thursday, May 30, 2002 3:23 PM
To: aspx_beginners
Subject: [aspx_beginners] RE: You've been there before...


This is the key reason why I think books should have their examples
*working* online, so that if you get stuck like this you can go and see the
actual working code and know for certain that the code really does work
(since so many book examples do not work).

<plug>Which is why ASP.NET By Example has all of its examples online at
http://aspauthors.com/aspnetbyexample/</plug>

Steve


Steven Smith, MCSE+Internet, Microsoft MVP: ASP.NET
ssmith@a...
President, ASPAlliance.com
http://aspalliance.com    The #1 ASP.NET Community
http://aspsmith.com        ASP.NET Training for ASP Developers

Learning ASP.NET?  Get My Book: ASP.NET By Example
http://amazon.com/exec/obidos/ASIN/0789725622/stevenatorasp/
----- Original Message -----
From: "Farrell, Timothy" <Timothy.Farrell@C...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Thursday, May 30, 2002 1:09 PM
Subject: [aspx_beginners] RE: You've been there before...


> Minh,
>
> Sorry about the ommition, it was this line :
> Dim SqlCmd As New StringBuilder()
>
> I surely didn't mean that I was out to slam the authors.  To a large
extent
> I wouldn't be where I am in developing without their dedication and time
in
> writing the books.  You perspective is eye opening and I appreciate your
> thoughts.
>
> As you indicated, the Imports System.Text namespace was not included in
the
> documentation.  Once I incorporated your thoughts into the script, the
error
> was gone.
>
> Thank you so much.
>
>
> However, now I am getting an error when I press the update link.  Here is
> the error:
>
> System.ArgumentOutOfRangeException: Specified argument was out of the
range
> of valid values. Parameter name: index.
>
> Once again the code:
> Imports System
> Imports System.Web
> Imports System.Web.UI
> Imports System.Web.UI.WebControls
> Imports System.Text
> Imports System.Data
> Imports System.Data.SqlClient
>
>
> Public Class A1 : Inherits Page
>     Protected DGEmployee As DataGrid
>
>     Private sSQLCon As String 
> "server=ntphoenix;database=plan;uid=sa;pwd=;"
>
>     Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
>
>
>         If Not Page.IsPostBack Then
>             Bind()
>         End If
>     End Sub
>
>     Protected Sub PageIndexChanged_OnClick(ByVal Sender As Object, ByVal E
> As DataGridPageChangedEventArgs)
>         DGEmployee.CurrentPageIndex = E.NewPageIndex
>         Bind()
>     End Sub
>
>
>     Private Sub Bind()
>         Dim SQLCon As New SqlConnection(sSQLCon)
>         Dim SqlCmd As New StringBuilder()
>         SqlCmd.Append("Select * FROM Employee")
>         Dim sda As New SqlDataAdapter(SqlCmd.ToString(), SQLCon)
>         Dim ds As New DataSet()
>         sda.Fill(ds, "employee")
>         DGEmployee.DataSource = ds.Tables("Employee").DefaultView
>         DGEmployee.DataBind()
>
>     End Sub
>
>     Public Sub DGEmployee_Edit(ByVal sender As Object, ByVal e As
> DataGridCommandEventArgs)
>
>         DGEmployee.EditItemIndex = e.Item.ItemIndex
>         Bind()
>
>     End Sub
>
>     Public Sub DGEmployee_Cancel(ByVal sender As Object, ByVal e As
> DataGridCommandEventArgs)
>
>         DGEmployee.EditItemIndex = -1
>         Bind()
>
>     End Sub
>
>     Public Sub DGEmployee_Update(ByVal sender As Object, ByVal e As
> DataGridCommandEventArgs)
>
>         Dim sInitials, sLastName, sFirstName, sUID, sPWD, sSecurity, sID
As
> String
>         sInitials = CType(e.Item.Cells(1).Controls(0), TextBox).Text
>         sLastName = CType(e.Item.Cells(2).Controls(0), TextBox).Text
>         sFirstName = CType(e.Item.Cells(3).Controls(0), TextBox).Text
>         sUID = CType(e.Item.Cells(4).Controls(0), TextBox).Text
>         sPWD = CType(e.Item.Cells(5).Controls(0), TextBox).Text
>         sSecurity = CType(e.Item.Cells(6).Controls(0), TextBox).Text
>         sID = e.Item.Cells(7).Text
>
>         Dim sSqlCmd As New StringBuilder()
>         sSqlCmd.Append("Update Employee ")
>         sSqlCmd.Append("Set Initials = @Initials,")
>         sSqlCmd.Append("LastName = @LastName,")
>         sSqlCmd.Append("FirstName = @FirstName,")
>         sSqlCmd.Append("UID = @UID,")
>         sSqlCmd.Append("PWD = @PWD,")
>         sSqlCmd.Append("Security = @Security,")
>         sSqlCmd.Append("WHERE ID = @ID,")
>
>         Dim SqlCon As New SqlConnection(sSQLCon)
>         Dim SqlCmd As New SqlCommand(sSqlCmd.ToString(), SqlCon)
>         SqlCmd.Parameters.Add(New SqlParameter("@Initials",
> SqlDbType.NVarChar, 8))
>         SqlCmd.Parameters("@Initials").Value = sInitials
>         SqlCmd.Parameters.Add(New SqlParameter("@LastName",
> SqlDbType.NVarChar, 50))
>         SqlCmd.Parameters("@LastName").Value = sLastName
>         SqlCmd.Parameters.Add(New SqlParameter("@FirstName",
> SqlDbType.NVarChar, 50))
>         SqlCmd.Parameters("@FirstName").Value = sFirstName
>         SqlCmd.Parameters.Add(New SqlParameter("@UID", SqlDbType.NVarChar,
> 10))
>         SqlCmd.Parameters("@UID").Value = sUID
>         SqlCmd.Parameters.Add(New SqlParameter("@PWD", SqlDbType.NVarChar,
> 10))
>         SqlCmd.Parameters("@PWD").Value = sPWD
>         SqlCmd.Parameters.Add(New SqlParameter("@Security", SqlDbType.Int,
> 3))
>         SqlCmd.Parameters("@Security").Value = sSecurity
>         SqlCmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int, 3))
>         SqlCmd.Parameters("@ID").Value = sID
>
>         SqlCon.Open()
>         SqlCmd.ExecuteNonQuery()
>         SqlCon.Close()
>
>         DGEmployee.EditItemIndex = -1
>         Bind()
>
>     End Sub
>
> End Class
>
>
> Sincerely,
>
> Tim
>
>
>
>
> The contents of this e-mail are intended for the named addressee only. It
> contains information that may be confidential. Unless you are the named
> addressee or an authorized designee, you may not copy or use it, or
disclose
> it to anyone else. If you received it in error please notify us
immediately
> and then destroy it.
>
>
>





The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it. 


  Return to Index