473,769 Members | 5,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Quickstart Problem

I'm trying to use the Insert.aspx Quickstart and I'm getting a NULL pointer
exception. Any help?

<code>
<script language="VB" runat="server">
Dim myConnection As SqlConnection

Sub Page_Load(Src As Object, e As EventArgs)
' Create a connection to the SQL Server
myConnection = New SqlConnection(" Data Source=SERVER;" _
& "Initial Catalog=databas e;User Id=user;Passwor d=password;")
' Check whether this page is a postback. If it is not
' a postback, call a custom BindGrid function.
If Not IsPostBack Then
BindGrid()
End If
End Sub

' Implement an AddAsset_Click function. This function does some data
' validation on the input form and builds a parameterized command
containing
' all the fields of the input form. Then it executes this command to the
' database and tests (using the try command) whether the data was added.
' Finally, it rebinds the DataGrid to show the new data.
Sub AddAsset_Click( Sender As Object, e As EventArgs)
Dim myCommand As SqlCommand
Dim insertCmd As String
' Check the Cube and Computer Serial input values and make sure they
are not
' empty. If they are empty, show a message to the user and rebind the
DataGrid.
If (cube.Value = "" Or computer_serial .Value = "")
Message.InnerHt ml = "ERROR: You MUST enter a Cube and Computer S/N "
Message.Style(" color") = "red"
BindGrid()
Exit Sub
End If
' Build a SQL INSERT statement string for all the input-form
' field values.
insertCmd = "insert into myTable values (@cube, @monitor_type,
@monitor_serial , @acd, " _
& "@ext, @computer_type, @computer_seria l, @hostname,
@second_comp_se rial, @second_hostnam e);"
' Initialize the SqlCommand with the new SQL string.
myCommand = New SqlCommand(inse rtCmd, myConnection)

' Create new parameters for the SqlCommand object and
' initialize them to the input-form field values.

'Cube data
myCommand.Param eters.Add(New SqlParameter("@ cube", _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@cube"). Value = cube.Value

'Monitor Type data
myCommand.Param eters.Add(New SqlParameter("@ monitor_type", _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@monitor _type").Value = monitor_type.Va lue

'Monitor Serial data
myCommand.Param eters.Add(New SqlParameter("@ monitor_serial" , _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@monitor _serial").Value = monitor_serial. Value

'ACD (position ID) data
myCommand.Param eters.Add(New SqlParameter("@ acd", _
SqlDbType.VarCh ar, 4))
myCommand.Param eters("@acd").V alue = acd.Value

'Extension data
myCommand.Param eters.Add(New SqlParameter("@ ext", _
SqlDbType.VarCh ar, 12))
myCommand.Param eters("@ext").V alue = ext.Value

'Computer Type data
myCommand.Param eters.Add(New SqlParameter("@ computer_type", _
SqlDbType.VarCh ar, 20))
myCommand.Param eters("@compute r_type").Value = computer_type.V alue

'Computer Serial data
myCommand.Param eters.Add(New SqlParameter("@ computer_serial ", _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@compute r_serial").Valu e = computer_serial .Value

'Hostname data
myCommand.Param eters.Add(New SqlParameter("@ hostname", _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@hostnam e").Value = hostname.Value

'2nd Computer Serial data
myCommand.Param eters.Add(New SqlParameter("@ second_comp_ser ial", _
SqlDbType.VarCh ar,50))
myCommand.Param eters("@second_ comp_serial").V alue =
second_comp_ser ial.Value

'2nd Hostname data
myCommand.Param eters.Add(New SqlParameter("@ second_hostname ", _
SqlDbType.VarCh ar,50))
myCommand.Param eters("@second_ hostname").Valu e = second_hostname .Value

myCommand.Conne ction.Open() THIS IS WHERE THE EXCEPTION IS
' Test whether the new row can be added and display the
' appropriate message box to the user.
Try
myCommand.Execu teNonQuery()
Message.InnerHt ml = "<b>Record Added</b><br>" & insertCmd
Catch ex As SqlException
If ex.Number = 2627 Then
Message.InnerHt ml = "ERROR: A record already exists with " _
& "the same Computer Serial Number"
Else
Message.InnerHt ml = "ERROR: Could not add record, please " _
& "ensure the fields are correctly filled out"
Message.Style(" color") = "red"
End If
End Try

myCommand.Conne ction.Close()
BindGrid()
End Sub

' BindGrid connects to the database and implements a SQL
' SELECT query to get all the data in the table
' of the database.
Sub BindGrid()
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
' Create a connection to the "database" SQL Server
myConnection = New SqlConnection(" data source=SERVER;" _
& "user id=user;passwor d=password;init ial catalog=Databas e")
' Connect to the SQL database using a SQL SELECT query to get all
' the data from the table.
myCommand = New SqlDataAdapter( "SELECT * FROM myTable", _
myConnection)
' Create and fill a new DataSet.
Dim ds As DataSet = New DataSet()
myCommand.Fill( ds)
' Bind the DataGrid control to the DataSet.
dgInserted.Data Source = ds
dgInserted.Data Bind()
End Sub
</script>
</code>
I'm getting a NULL pointer exception on:

myCommand.Conne ction.Open()
Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
ASP.conInsert_a spx.AddAsset_Cl ick(Object Sender, EventArgs e) in
C:\inventory\In sert.aspx:96
System.Web.UI.H tmlControls.Htm lInputButton.On ServerClick(Eve ntArgs e)

System.Web.UI.H tmlControls.Htm lInputButton.Sy stem.Web.UI.IPo stBackEventHand ler.RaisePostBa ckEvent(String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
System.Web.UI.P age.ProcessRequ estMain()

Everything looks good to me. Most of the code is from the MSDN Quickstart
and I've just tweaked it to allow for my database.

AM I MISSING SOMETHING?
Nov 19 '05 #1
1 1541
Pat
Eustice mabe something is wrong with your connectionStrin g?
PAtrick

"Eustice Scrubb" <Eu***********@ discussions.mic rosoft.com> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
I'm trying to use the Insert.aspx Quickstart and I'm getting a NULL pointer exception. Any help?

<code>
<script language="VB" runat="server">
Dim myConnection As SqlConnection

Sub Page_Load(Src As Object, e As EventArgs)
' Create a connection to the SQL Server
myConnection = New SqlConnection(" Data Source=SERVER;" _
& "Initial Catalog=databas e;User Id=user;Passwor d=password;")
' Check whether this page is a postback. If it is not
' a postback, call a custom BindGrid function.
If Not IsPostBack Then
BindGrid()
End If
End Sub

' Implement an AddAsset_Click function. This function does some data
' validation on the input form and builds a parameterized command
containing
' all the fields of the input form. Then it executes this command to the ' database and tests (using the try command) whether the data was added. ' Finally, it rebinds the DataGrid to show the new data.
Sub AddAsset_Click( Sender As Object, e As EventArgs)
Dim myCommand As SqlCommand
Dim insertCmd As String
' Check the Cube and Computer Serial input values and make sure they
are not
' empty. If they are empty, show a message to the user and rebind the DataGrid.
If (cube.Value = "" Or computer_serial .Value = "")
Message.InnerHt ml = "ERROR: You MUST enter a Cube and Computer S/N " Message.Style(" color") = "red"
BindGrid()
Exit Sub
End If
' Build a SQL INSERT statement string for all the input-form
' field values.
insertCmd = "insert into myTable values (@cube, @monitor_type,
@monitor_serial , @acd, " _
& "@ext, @computer_type, @computer_seria l, @hostname,
@second_comp_se rial, @second_hostnam e);"
' Initialize the SqlCommand with the new SQL string.
myCommand = New SqlCommand(inse rtCmd, myConnection)

' Create new parameters for the SqlCommand object and
' initialize them to the input-form field values.

'Cube data
myCommand.Param eters.Add(New SqlParameter("@ cube", _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@cube"). Value = cube.Value

'Monitor Type data
myCommand.Param eters.Add(New SqlParameter("@ monitor_type", _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@monitor _type").Value = monitor_type.Va lue

'Monitor Serial data
myCommand.Param eters.Add(New SqlParameter("@ monitor_serial" , _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@monitor _serial").Value = monitor_serial. Value

'ACD (position ID) data
myCommand.Param eters.Add(New SqlParameter("@ acd", _
SqlDbType.VarCh ar, 4))
myCommand.Param eters("@acd").V alue = acd.Value

'Extension data
myCommand.Param eters.Add(New SqlParameter("@ ext", _
SqlDbType.VarCh ar, 12))
myCommand.Param eters("@ext").V alue = ext.Value

'Computer Type data
myCommand.Param eters.Add(New SqlParameter("@ computer_type", _
SqlDbType.VarCh ar, 20))
myCommand.Param eters("@compute r_type").Value = computer_type.V alue

'Computer Serial data
myCommand.Param eters.Add(New SqlParameter("@ computer_serial ", _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@compute r_serial").Valu e = computer_serial .Value
'Hostname data
myCommand.Param eters.Add(New SqlParameter("@ hostname", _
SqlDbType.VarCh ar, 50))
myCommand.Param eters("@hostnam e").Value = hostname.Value

'2nd Computer Serial data
myCommand.Param eters.Add(New SqlParameter("@ second_comp_ser ial", _
SqlDbType.VarCh ar,50))
myCommand.Param eters("@second_ comp_serial").V alue =
second_comp_ser ial.Value

'2nd Hostname data
myCommand.Param eters.Add(New SqlParameter("@ second_hostname ", _
SqlDbType.VarCh ar,50))
myCommand.Param eters("@second_ hostname").Valu e = second_hostname .Value
myCommand.Conne ction.Open() THIS IS WHERE THE EXCEPTION IS
' Test whether the new row can be added and display the
' appropriate message box to the user.
Try
myCommand.Execu teNonQuery()
Message.InnerHt ml = "<b>Record Added</b><br>" & insertCmd
Catch ex As SqlException
If ex.Number = 2627 Then
Message.InnerHt ml = "ERROR: A record already exists with " _
& "the same Computer Serial Number"
Else
Message.InnerHt ml = "ERROR: Could not add record, please " _
& "ensure the fields are correctly filled out"
Message.Style(" color") = "red"
End If
End Try

myCommand.Conne ction.Close()
BindGrid()
End Sub

' BindGrid connects to the database and implements a SQL
' SELECT query to get all the data in the table
' of the database.
Sub BindGrid()
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
' Create a connection to the "database" SQL Server
myConnection = New SqlConnection(" data source=SERVER;" _
& "user id=user;passwor d=password;init ial catalog=Databas e")
' Connect to the SQL database using a SQL SELECT query to get all
' the data from the table.
myCommand = New SqlDataAdapter( "SELECT * FROM myTable", _
myConnection)
' Create and fill a new DataSet.
Dim ds As DataSet = New DataSet()
myCommand.Fill( ds)
' Bind the DataGrid control to the DataSet.
dgInserted.Data Source = ds
dgInserted.Data Bind()
End Sub
</script>
</code>
I'm getting a NULL pointer exception on:

myCommand.Conne ction.Open()
Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
ASP.conInsert_a spx.AddAsset_Cl ick(Object Sender, EventArgs e) in
C:\inventory\In sert.aspx:96
System.Web.UI.H tmlControls.Htm lInputButton.On ServerClick(Eve ntArgs e)

System.Web.UI.H tmlControls.Htm lInputButton.Sy stem.Web.UI.IPo stBackEventHand l
er.RaisePostBac kEvent(String eventArgument) System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
System.Web.UI.P age.ProcessRequ estMain()

Everything looks good to me. Most of the code is from the MSDN Quickstart
and I've just tweaked it to allow for my database.

AM I MISSING SOMETHING?

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2187
by: Damon | last post by:
I installed a .NET on my windowsXP pro. And, I ran "C:\Program Files\Microsoft Visual Studio ..NET\FrameworkSDK\Samples\Setup\ConfigSamples.exe" and got same virtual directories. when I use this URL-http://localhost/quickstart to use Quickstart, the webpage could not display.IE always asks me to download "default.aspx". So, how to config IIS or something else to use Quickstart correctly?
0
1245
by: Scott Dunaway | last post by:
I have Windows XP Pro with the newest SP and all updates. I have Visual Studio .NET 2002 When I installed VS.NET I didn't add iis nor the SQL server but then I decided to reverse that decision while looking at the help files. I have tried doing as the ConfigDetails.htm says Run the following command: aspnet_regiis.exe -i
0
923
by: myleslawrence | last post by:
I hope this is the correct forum for this because I'm at wits end. I have a Win 2003 server, SQL server 2000 and the .Net framework sdk installed. The ASP.NET VB Quickstart tutorials have web form examples some of which connect to the database. They do not work and I get 'server does not exist or access denied' when I try to run any of the database examples. If I revert back to asp and write a simple asp program that does an ADODB
1
2765
by: t322y | last post by:
Hi All I installed Microsoft.Net Framework Version:1.0.3705.209 (included ASP.NET Version:1.0.3705.0) in my Win 2000 SP3 3 weeks ago. It worked well all until i installed a free softwore GoMono. I can't run asp.net quickstart tutorial. it kept asking some file like Microsoft.VisualBasic.DLL and Microsoft.VisualBasic.EXE. i tried to find the files manually and i found them in GoMono directory. i copied the files to Micrososft.NET directory...
1
1337
by: Abhishek Srivastava | last post by:
Hello All, I have installed the quick start samples that come along with .net sdk. I am facing some strange behavior on my machine. I would be gratefull if someone could explain what is going on. If I type http://15.76.221.178/quickstart in my browser I get an error message you are not authorized to view this page. If I type http://localhost/quickstart. by browser automatically goes to
2
1654
by: NNTP | last post by:
Hi, I tried to setup the quickstart and tutorial of ASP.NET framework in Window XP prof. with SP2. The system is running IIS and FrontPage 2000 server extension. I also downloaded the MSDE2000A.exe and started the NETSDK instance. However, when I opened the QuickStart page, it got the HTTP 500 error. Do you have any idea what's happening? Do I need to remove SP2 before setting up the SP1 on IE? Barry
4
1220
by: myleslawrence | last post by:
I hope this is the correct forum for this because I'm at wits end. I have a Win 2003 server, SQL server 2000 and the .Net framework sdk installed. The ASP.NET VB Quickstart tutorials have web form examples some of which connect to the database. They do not work and I get 'server does not exist or access denied' when I try to run any of the database examples. If I revert back to asp and write a simple asp program that does an ADODB
3
1166
by: moondaddy | last post by:
I'm checking out the Ent Lib for the first time and tried to run the Quickstart for data access. upon clicking the first button in the sample app I get an error saying there may be an error trying to connect to sql server 2005.... Is this really expecting sql server 2005? or is this just the way the msg was keyed in? I'm running sql server 2000 which is where the entlib quickstart db is installed. Also, is there a more appropriate...
3
1215
by: stacy | last post by:
On my XP Pro laptop, I have installed IIS, MSDE and QuickStart Samples but am encountering the following error when I click on any of the QuickStarts on the Microsoft.NET Framework SDK QuickStarts page. "You are not authorized to view this page" from the . I may have done something wrong in installing the MSDE, here are the steps I went through I was logged in as myself on a domain
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.