Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 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 October 10th, 2003, 06:17 AM
Registered User
 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default i need help with this vb.net error message!!

i am able to display a database.mdb in a datagrid but everytime i try to add a record to the database i get the error message "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."

here is my code:

-----------------------------------------------------------------

Imports System.Data
Imports System.Data.OleDb

Public Class WebForm1
    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()

    End Sub
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label

    '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


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strConn As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("/clarks03/newapp/database123.mdb") & ";"
        Dim query As String = "select * from [database]" 'select * from [database]
        Dim MyConnection As New OleDbConnection(strConn)
        Dim objconn As New OleDb.OleDbConnection(strConn)
        Dim myCmd As New OleDbCommand(query, MyConnection)

        Dim objdataadapter As New OleDb.OleDbDataAdapter(query, MyConnection)
        Dim dataset1 As DataSet = New DataSet("MyDetails")


        MyConnection.Open()


        Dim NewRow As DataRow
        NewRow = dataset1.Tables("database").NewRow
        NewRow.Item("major") = TextBox1.Text
        dataset1.Tables("database").Rows.Add(NewRow)


        DataGrid1.DataSource = dataset1
        DataGrid1.DataBind()
        MyConnection.Close()



    End Sub
End Class

-----------------------------------------------------------------

cheers in advance

 
Old October 10th, 2003, 06:21 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 there,

If you debug your application, on what line does it crash? How does your ASPX file look like? Are all the controls you declare in the Code Behind present in the ASPX file?

Also, can you please not post the same post in multiple forums? Your message will be read anyway....

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 13th, 2003, 08:16 PM
Registered User
 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It doesn't appear that you're populating the dataset so the call to dataset1.Tables("database") is going to return null (Nothing in VB) so the .NewRow will raise the exception you noted.

You need to call DataAdapter.Fill(Dataset)







Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Message: Asp.Net Server failed to start ... ramakrishna.one .NET Framework 2.0 0 June 9th, 2007 03:23 AM
LNK2019 Error message - Visual C++ .net 2003 Gino Visual C++ 2 December 18th, 2005 10:06 AM
error message using ssl : "VS .NET cannot create.. connect2sandep ASP.NET 1.0 and 1.1 Professional 0 October 20th, 2005 11:37 AM
Simple ASP.NET message box with VB janicen General .NET 1 February 24th, 2005 03:31 AM
"Server not running ASP.NET 1.1" error message arashj General .NET 1 September 7th, 2004 05:49 AM





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