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
|