Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 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 April 26th, 2004, 11:02 AM
Authorized User
 
Join Date: Apr 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mahir
Default Ch13 EditingData.aspx

Hi,

I am in deep trouble I bought the book and going alongso nicely that I am enjoying it but my party ruined when this error occured.

It says that array is out of bound in EditingData.aspx in Chapter 13 I said Ok lets try another example that is synchronize.aspx and it says the problem like updatable query is required. can any body here help me please I need it urgent.

Thanks
Mahir Ali Ahmed

Mahir Ali Ahmed
__________________
Mahir Ali Ahmed
 
Old April 26th, 2004, 11:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Can you post any code? I don't have the book.
 
Old April 26th, 2004, 11:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Mahir,

Can you please post the relevant parts of the code you're having troubles with? Makes it easier to see what's going on.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Bulls On Parade by Rage Against The Machine (Track 2 from the album: Evil Empire) What's This?

 
Old April 27th, 2004, 04:22 AM
Authorized User
 
Join Date: Apr 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mahir
Default

I am using WindowsXp Pro and I amworking at home so i don't have any toher pc connected to mine, i have .net sdk and iis 5.1 i will send the code as soon as i reach home may be tomorrow.

Thanks
Mahir

Mahir Ali Ahmed
 
Old April 27th, 2004, 10:57 AM
Authorized User
 
Join Date: Apr 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mahir
Default

Here is the code
Sub Page_Load(Source As Object, E As EventArgs)

    Dim strConnection As String
    Dim strSQL As String
    Dim ObjDataSet As New DataSet()
    Dim objConnection As OleDbConnection
    Dim objAdapter As OleDbDataAdapter

    strConnection = "Provider=Microsoft.Jet.OleDb.4.0; " & _
                    "Data Source = D:\BegASPNET\Ch13\Northwind.mdb"

    strSQL = "SELECT FirstName, LastName From Employees;"

    objConnection = New OleDBConnection(strConnection)'
    objAdapter = New OleDbDataAdapter(strSQL, objConnection)

    objAdapter.Fill(objDataSet, "Employees")

    dgNameList1.DataSource = objDataSet.Tables("Employees").DefaultView
    dgNameList1.DataBind()

    '------------------------------------------------------------
    'Marker 1
    'Adding Row

    Dim objTable As DataTable
    Dim objNewRow As DataRow

    objTable = objDataSet.Tables("Employees")
    objNewRow = objTable.NewRow()

    objNewRow.Item("FirstName") = "Norman"
    objNewRow.Item("LastName") = "Blake"

    objTable.Rows.Add(objNewRow)

    'bind the data grid to new data

    dgNameList2.DataSource = objTable.DefaultView
    dgNameList2.DataBind()

    '------------------------------------------------------------
    'Marker 2
    'Editing Row

    dim objRows() As DataRow

    'Find the Row to change data

    objRows = objTable.Select("FirstName='Margaret' AND LastName='Peacock'")

    objRows(0).Item("FirstName") = "John"
    objRows(0).Item("LastName") = "Hartford"

    'bind the data grid o the new data

    dgNameList3.DataSource = objTable.DefaultView
    dgNameList3.DataBind()

    '------------------------------------------------------------
    'Marker 3
    'Delete a Row

    'The Row Collection is 0 Indexed, so this this removes the sixth row

    objTable.Rows(5).Delete()

    'bind the data grid to new data

    dgNameList4.DataSource = objTable.DefaultView
    dgNameList4.DataBind()



End Sub

Please reply as soon as possible.
Thankx

Mahir Ali Ahmed
 
Old April 27th, 2004, 11:00 AM
Authorized User
 
Join Date: Apr 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mahir
Default

I have problem in editing everything else is fine

it give an error called array out of bound

Server Error in '/BegASPNET' 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 55: objRows = objTable.Select("FirstName='Margaret' AND LastName='Peacock'")
Line 56:
Line 57: objRows(0).Item("FirstName") = "John"
Line 58: objRows(0).Item("LastName") = "Hartford"
Line 59:


Source File: D:\BegASPNET\Ch13\EditingData.aspx Line: 57

Stack Trace:


[IndexOutOfRangeException: Index was outside the bounds of the array.]
   ASP.EditingData_aspx.Page_Load(Object Source, EventArgs E) in D:\BegASPNET\Ch13\EditingData.aspx:57
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +29
   System.Web.UI.Page.ProcessRequestMain() +724




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

Mahir Ali Ahmed
 
Old April 27th, 2004, 11:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Mahir,

I think that your Select method doesn't return a valid record. I looked at the database that comes with the code download, and there is no record for Margaret, Peacock but there is one for John, Hartford. What I think is that the code has already ran on the database and updated the record.
Anyway, this is a nice learning experience as you should always cater for situations where the data doesn't show up as expected. The Select method returns an Array with a Length of zero when no records are found, so you can check for that:
Code:
Dim objRows() As DataRow
'Find the Row to change data
objRows = objTable.Select("FirstName='Margaret' AND LastName='Peacock'")

If objRows.Length = 0 Then
  ' Record not found. Do whatever you need to do here
Else
  ' Do the update
    objRows(0).Item("FirstName") = "John"
    objRows(0).Item("LastName") = "Hartford"
End If
This way, the code will only try to update the record when it was found.

Please understand that this is a public forum where people offer their time and support on a voluntary basis. Requesting people to "reply as soon as possible" may not always be the tone that receives the best or fastest responses....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Escape by Muse (Track 10 from the album: Showbiz) What's This?

 
Old April 28th, 2004, 03:05 AM
Authorized User
 
Join Date: Apr 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mahir
Default

HI,

I am sorry about my tone and i am very thankfull to imar who helped me thanks alot i need an help on another file also can i submit that too.

Thanks

Mahir Ali Ahmed
 
Old April 28th, 2004, 03:25 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, no problem. Don't worry about that. Glad it's working now.

If the other file deals with a different topic, I suggest you create a new post for it. Makes it easier to read and answer....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch13 Case Study 2 alecwood BOOK: Beginning Access 2003 VBA 0 October 18th, 2007 05:40 AM





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