Wrox Programmer Forums
|
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 May 20th, 2005, 01:54 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am confused. Why I create dataset n name it as DsBooks, but the dataset created is DsBooks1 in designer, while DsBooks.xsd in solution explorer, which name should I use in coding?

Now the page hv following error, I din understand.

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

Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 89:
Line 90: 'NOTE: The following placeholder declaration is required by the Web Form Designer.
Line 91: 'Do not delete or move it.
Line 92: Private designerPlaceholderDeclaration As System.Object
Line 93:


Source File: c:\inetpub\wwwroot\e-library\Borrow1.aspx.vb Line: 91

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   e_library.Borrow11.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\e-library\Borrow1.aspx.vb:91
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750




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

Code:
Imports System.Data
Imports System.Data.SqlClient

Public Class Borrow11
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
        Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
        Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
        Me.DsBooks = New e_library.DsBooks
        CType(Me.DsBooks, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'SqlDataAdapter1
        '
        Me.SqlDataAdapter1.DeleteCommand = Me.SqlDeleteCommand1
        Me.SqlDataAdapter1.InsertCommand = Me.SqlInsertCommand1
        Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
        Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Material_Table1", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("seqNo", "seqNo"), New System.Data.Common.DataColumnMapping("title", "title"), New System.Data.Common.DataColumnMapping("title_id", "title_id")})})
        Me.SqlDataAdapter1.UpdateCommand = Me.SqlUpdateCommand1
        '
        'SqlDeleteCommand1
        '
        Me.SqlDeleteCommand1.CommandText = "DELETE FROM Material_Table1 WHERE (seqNo = @Original_seqNo) AND (title_id = @Orig" & _
        "inal_title_id) AND (title = @Original_title)"
        Me.SqlDeleteCommand1.Connection = Me.SqlConnection1
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_seqNo", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "seqNo", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_title_id", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "title_id", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlDeleteCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_title", System.Data.SqlDbType.VarChar, 100, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "title", System.Data.DataRowVersion.Original, Nothing))
        '
        'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = "workstation id=PMEMH227;packet size=4096;user id=sa;data source=PMEMH227;persist " & _
        "security info=False;initial catalog=""E-Library Records"""
        '
        'SqlInsertCommand1
        '
        Me.SqlInsertCommand1.CommandText = "INSERT INTO Material_Table1(title, title_id) VALUES (@title, @title_id); SELECT s" & _
        "eqNo, title, title_id FROM Material_Table1 WHERE (seqNo = @@IDENTITY) AND (title" & _
        "_id = @title_id)"
        Me.SqlInsertCommand1.Connection = Me.SqlConnection1
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@title", System.Data.SqlDbType.VarChar, 100, "title"))
        Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@title_id", System.Data.SqlDbType.VarChar, 10, "title_id"))
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "SELECT seqNo, title, title_id FROM Material_Table1"
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = "UPDATE Material_Table1 SET title = @title, title_id = @title_id WHERE (seqNo = @O" & _
        "riginal_seqNo) AND (title_id = @Original_title_id) AND (title = @Original_title)" & _
        "; SELECT seqNo, title, title_id FROM Material_Table1 WHERE (seqNo = @seqNo) AND " & _
        "(title_id = @title_id)"
        Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@title", System.Data.SqlDbType.VarChar, 100, "title"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@title_id", System.Data.SqlDbType.VarChar, 10, "title_id"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_seqNo", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "seqNo", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_title_id", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "title_id", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_title", System.Data.SqlDbType.VarChar, 100, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "title", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@seqNo", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "seqNo", System.Data.DataRowVersion.Current, Nothing))
        '
        'DsBooks1
        '
        Me.DsBooks.DataSetName = "DsBooks"
        Me.DsBooks.Locale = New System.Globalization.CultureInfo("en-AU")
        CType(Me.DsBooks, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub
    Protected WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
    Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
    Protected WithEvents DsBooks As e_library.DsBooks
    Protected WithEvents DataGridBook As System.Web.UI.WebControls.DataGrid
    Protected WithEvents DsBooks As e_library.DsBooks
    Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlUpdateCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlDeleteCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents DsBooks1 As e_library.DsBooks
    Protected WithEvents lblBooks As System.Web.UI.WebControls.Label
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SqlDataAdapter1.Fill(DsBooks)
        DataGridBook.DataSource = DsBooks
        DataGridBook.DataBind()
    End Sub

    Private Sub SqlDataAdapter1_RowUpdated(ByVal sender As System.Object, ByVal e As System.Data.SqlClient.SqlRowUpdatedEventArgs) Handles SqlDataAdapter1.RowUpdated

    End Sub

    Private Sub DataGridBook_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridBook.SelectedIndexChanged

    End Sub
End Class
The code is a bit long, i not sure is it the problem with the designer code.

Thanks a lot!

 
Old May 20th, 2005, 03:00 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you changed any code between #Region and #End Region?
I see that the following code is appearing twice:
  Protected WithEvents DsBooks As e_library.DsBooks
I wonder how it did not give you an error at compile time???

 
Old May 20th, 2005, 05:27 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I do some changes on the name of Dataset, last time is DsBooks1, now is DsBooks. But before I change the name of dataset, it already hv more than 1 line about DsBooks. So I change the name accordingly.

actually I get build error
"DsBooks is already declared as 'Protected Dim WithEvents DsBooks As e_library.DsBooks' in this class"

But i don't know what to do with it.

Then when i run it, get the error as in previous post.

 
Old May 20th, 2005, 05:36 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try deleting the duplicate line:

Protected WithEvents DsBooks As e_library.DsBooks




 
Old May 20th, 2005, 06:32 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Even though i delete the duplicate line, the same error is still displayed.

 
Old May 20th, 2005, 06:43 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would suggest that you delete the data adapter, connection and
dataset created in the designer. Create them again. If you want to
rename the dataset name, do that in the Properties window (Name property).
Make the relevant changes in the code behind for binding the datagrid


 
Old May 23rd, 2005, 09:09 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It works finally. Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort data in a data grid? zaheerabbas.sk ASP.NET 1.0 and 1.1 Basics 3 April 10th, 2007 02:37 PM
Export data from data grid to excel pomoc VB.NET 2002/2003 Basics 0 December 16th, 2005 03:11 PM
Export data from data grid to Excel pomoc Visual Basic 2005 Basics 0 December 16th, 2005 02:56 PM
trying to load db data into data grid itsajourney Beginning VB 6 2 June 7th, 2005 12:05 PM
About data grid Asteroid ASP.NET 1.0 and 1.1 Basics 4 December 9th, 2004 05:42 AM





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