Hi guys.. i need help please... im new and already pulling my hair out!
error -
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 38:
Line 39: Dim objAnswer As Object = comm.ExecuteScalar()
Line 40: TextBox1.Text = objAnswer.ToString()
Line 41: conn.Close()
Line 42: End Sub |
Source File: D:\Sean\JVX\welcomechange.aspx.vb Line: 40
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
welcomechange.TextBox1_Load(Object sender, EventArgs e) in D:\Sean\JVX\welcomechange.aspx.vb:40
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
|
and here's my code -
1 Imports System.Data.SqlClient
2 Imports System.Configuration
3
4 Partial Class welcomechange
5 Inherits System.Web.UI.Page
6
7
8 Dim welcJVR As String = ConfigurationManager.ConnectionStrings("JVRwelcome").ConnectionString
9
10 Sub welcome()
11 Dim conn As New SqlConnection(welcJVR)
12 Dim comm As New SqlCommand("welcome", conn)
13 conn = New SqlConnection(welcJVR)
14 conn.Open()
15 comm = New SqlCommand("update JVR_welcome set welcomenote=('" & TextBox1.Text & "') where id=1 ")
16 comm.Connection = conn
17 comm.ExecuteNonQuery()
18 conn.Close()
19
20
21
22 End Sub
23
24 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
25 welcome()
26 Response.Redirect("admin.asp")
27 End Sub
28
29 Protected Sub TextBox1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Load
30
31 Dim conn As New SqlConnection(welcJVR)
32 Dim comm As New SqlCommand("welcomefill", conn)
33 conn = New SqlConnection(welcJVR)
34 conn.Open()
35 comm = New SqlCommand("select welcomenote from JVR_welcome")
36 comm.Connection = conn
37
38
39 Dim objAnswer As Object = comm.ExecuteScalar()
40 TextBox1.Text = objAnswer.ToString()
41 conn.Close()
42 End Sub
43 End Class
44
thanks for any help:)