Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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
 
Old April 19th, 2004, 10:19 AM
Authorized User
 
Join Date: Sep 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cjcd
Default INSERT Not working


<code>
Sub doInsert(Source as Object, E as EventArgs)

          Dim strConn as String = ConfigurationSettings.AppSettings("myDSN")
    Dim MySQL as string = "Insert into propertiesMatrix ([propertyType],
[location], [zone], [aream2], [price], [currency], [charac], [comments],
[picture], [uploadedby], [updDate]) "
           MySQL += "Values (@propertyType, @location, @zone, @aream2,
@price, @currency, @charac, @comments, @picture, @uploadedby, @updDate)"

    Dim MyConn as New OleDbConnection(strConn)
    Dim Cmd as New OleDbCommand(MySQL, MyConn)

    With Cmd.Parameters
        .Add(New OleDbParameter("@propertyType", typelist.SelectedItem.text))
        .Add(New OleDbParameter("@location", location.text))
        .Add(New OleDbParameter("@zone", zonelist.SelectedItem.text))
        .Add(New OleDbParameter("@aream2", area.text))
        .Add(New OleDbParameter("@price", price.text))
        .Add(New OleDbParameter("@currency", currencylist.SelectedItem.text))
        .Add(New OleDbParameter("@charac", charac.text))
        .Add(New OleDbParameter("@comments", comments.text))
        .Add(New OleDbParameter("@picture",
"http://localhost/images/internal/nopic.gif"))
        .Add(New OleDbParameter("@uploadedby", userlist.SelectedItem.text))
        .Add(New OleDbParameter("@updDate", Format(DateTime.Now(),
"dd-MMM-yyyy")))
    End With
    MyConn.Open()
    cmd.ExecuteNonQuery()

    MyConn.Close

    response.redirect("default.aspx")
  End Sub
</code>

Do you have any idea why this doesn't work? The error is:

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 113:
Line 114: With Cmd.Parameters
Line 115: .Add(New OleDbParameter("@propertyType",
typelist.SelectedItem.text))
Line 116: .Add(New OleDbParameter("@location", location.text))
Line 117: .Add(New OleDbParameter("@zone",
zonelist.SelectedItem.text))


 
Old April 19th, 2004, 10:27 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I think you're better off asking these kind of .NET questions in an ASP.NET forum. This for is for classic ASP, not ASP.NET.

Anyway, do all your controls exist on the page? That is, when you debug, does "typelist.SelectedItem" (and all the others you assign to the Params) result in a valid control with a valid Text property?

Either debug the page and set a breakpoint to find out, or add the value of the controls to a Label right before you add them to the Parameters collection. This allows you to see which control is causing the problem.

If that doesn't help, maybe you should post some more code of the rest of the page (including the ASPX part)

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Star Guitar by The Chemical Brothers (Track 4 from the album: Come With Us)






Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Web.Config..Working or Not Working peace95 ASP.NET 1.0 and 1.1 Basics 1 September 18th, 2006 06:53 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
Insert into statement not working. alisonchase Access ASP 8 January 16th, 2005 10:52 AM





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