VS.NET 2002/2003Discussions 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
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."
'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)
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.
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.