Wrox Programmer Forums
|
All Other Wrox Books Do you have a question about a Wrox book that isn't listed anywhere on p2p.wrox.com or where the forum is locked? Here's a forum to post questions about any other Wrox book so that other readers or one of the authors can help you with your questions. IF YOU ARE LOOKING FOR CODE DO NOT ASK "Where can I find the code for this book?" That question is answered here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the All Other Wrox Books 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
  #1 (permalink)  
Old October 10th, 2003, 05:55 AM
Registered User
 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default i need help with my vb.net code

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

  #2 (permalink)  
Old February 10th, 2005, 09:29 AM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have the same problem, any help?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with vb.net code Brettvan1 VB.NET 2002/2003 Basics 2 June 1st, 2005 09:41 AM
Can'T find code to Beginning Asp.net using VB.NET darruler All Other Wrox Books 1 August 12th, 2004 05:04 PM
ASP.NET Using VB.NET Chapt 3 Code error? uh6uj All Other Wrox Books 1 February 26th, 2004 10:46 AM
Help 'beginning asp.net using vb.net' source code jkmf Wrox Book Feedback 1 January 18th, 2004 08:09 AM





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