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 January 26th, 2005, 11:33 AM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default any idea's on this one?

 Exception Details: System.Data.SqlClient.SqlException: Prepared statement '(@FirstName nvarchar(4000),@LastName nvarchar(4000),@PhoneNumber' expects parameter @RecommendToken, which was not supplied.

Source Error:

Line 30: cmdInsert.Parameters.Add( "@UniqueID", request.form("txtUniqueID"))
Line 31: ConTRSS.Open()
Line 32: cmdInsert.ExecuteNonQuery()
Line 33: ConTRSS.Close()
Line 34: End Sub

your help is appreciated.

thanks,

Chris

 
Old January 26th, 2005, 01:16 PM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the stack trace if that helps...

[SqlException: Prepared statement '(@FirstName nvarchar(4000),@LastName nvarchar(4000),@PhoneNumber' expects parameter @RecommendToken, which was not supplied.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
   ASP.SecurIDTokenSurvey_aspx.Button_Click(Object s, EventArgs e) in c:\inetpub\wwwroot\securidtokensurvey.aspx:32
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1277




 
Old January 26th, 2005, 02:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you using a Stored Procedure? If so, do your variables in the sproc match with the parameters you attach to the SqlCommand object?

If that doesn't help, can you post more code, including the head of the stored procedure (with the param declarations)?

Imar
 
Old January 26th, 2005, 02:43 PM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Runat="Server">

Sub Button_Click( s As Object, e As EventArgs )
    Dim ConTRSS As SqlConnection
    Dim strInsert As String
    Dim cmdInsert As SqlCommand

    Dim strAuthHost, strUsrPath
    strAuthHost = "WinNT://websrv"
    strUsrPath = "WinNT://domain/websrv/"


  ConTRSS = New SqlConnection( "Server=***.***.***.***;UID=*********;Password=*** ****************;database=SecurIDToken_Survey" )
  strInsert = "Insert UserSurvey ( FirstName, LastName, PhoneNumber, EmailAddress, ConnectTo, Often, Easy, RecommendToken, PreferAlpha, Rating, Comments, UniqueID ) Values ( @FirstName, @LastName, @PhoneNumber, @EmailAddress, @ConnectTo, @Often, @Easy, @RecommendToken, @PreferAlpha, @Rating, @Comments, @UniqueID )"
  cmdInsert = New SqlCommand( strInsert, ConTRSS )
    cmdInsert.Parameters.Add( "@FirstName", request.form("txtFirstName"))
    cmdInsert.Parameters.Add( "@LastName", request.form("txtLastName"))
    cmdInsert.Parameters.Add( "@PhoneNumber", request.form("txtPhoneNumber"))
    cmdInsert.Parameters.Add( "@EmailAddress", request.form("txtEmailAddress"))
    cmdInsert.Parameters.Add( "@ConnectTo", request.form("txtConnectTo"))
    cmdInsert.Parameters.Add( "@Often", request.form("txtOften"))
    cmdInsert.Parameters.Add( "@Easy", request.form("txtEasy"))
    cmdInsert.Parameters.Add( "@RecommendToken", request.form("txtRecommendToken"))
    cmdInsert.Parameters.Add( "@PreferAlpha", request.form("txtPreferAlpha"))
    cmdInsert.Parameters.Add( "@Rating", request.form("txtRating"))
    cmdInsert.Parameters.Add( "@Comments", request.form("txtComments"))
    cmdInsert.Parameters.Add( "@UniqueID", request.form("txtUniqueID"))
  ConTRSS.Open()
  cmdInsert.ExecuteNonQuery()
  ConTRSS.Close()
End Sub


 
Old January 26th, 2005, 02:48 PM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm thinking maybe I have the data type set as a string and it shouldn't be explicitly declared. So hopefully if what I'm reading is correct it will be stored as an object then auto converted to the appropriate data type via "late binding". Though I'm really new at ASP.NET so that's the particular thing I'm about to try now. I feel like I'm going in circles on this one.

(For the record that was completely wrong.) I cut out the declaration of the string and the page wouldn't even load. I also tried declaring it as an object data type and that just gave the same error message. I also tried switching it to a char datatype and that gave a different error message... So in short I'm totally in the dark on this one.
 
Old January 26th, 2005, 05:26 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

AFAICS, things look like they should.

Are you sure there is a text box called txtRecommendToken with exactly the same spelling?

You can get this error when you run the code before the page has been posted back, so Request.Form doesn't exist yet. You can also get this error when you try to access a control that doesn't exist.

Try this:

cmdInsert.Parameters.Add( "@RecommendToken", request.form("txtRecommendToken").ToString())

This should convert the control's value to a string, which will fail if the control isn't found.

Better yet, and I don't understand why you aren't using it, access the Text property of the control instead of using the "old skool" Request.Form:

cmdInsert.Parameters.Add( "@RecommendToken", txtRecommendToken.Text)

This gives you intelli sense, compile time error checking, and much more benefits....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Instant Street by dEUS (From the album: The Ideal Crash) What's This?
 
Old January 27th, 2005, 04:28 PM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just wanted to say he was correct on the simple error on my part of not remembering to put txt inside of the variable "id" tags at about halfway down the page.

However on the second part if you read my other post, "Lost, please help me...". You will see why I used the "old way" as he called it.

Regardless, thanks man. That one had my whole office scratching our heads.

regards,

CW

 
Old January 27th, 2005, 05:46 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Right, I see.

I think, however, you misinterpreted the suggestion made in that post. Instead of changing the way you access the controls in code to match the Html input controls you use on the ASPX page, you should change the Html controls to true ASP controls in the ASPX portion of the page:

YourPage.aspx:
Code:
<form....>
  <asp:TextBox id="txtFirstName" runat="server" />
  <asp:TextBox id="txtLastName" runat="server" />
</form>
Then in the code behind of your page, add something like this:
Code:
Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
This code is necessary to hook up the controls in the ASPX file to the code in the Code Behind.

Now you can simply use txtFirstName.Text to get the text from your controls.

This is the way things are done in the .NET world. Like you found out, you can still use classic Html controls, and use Request.Form to access their contents, but this really isn't recommended anymore.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Control I'm Here (S.D.I. Mix) by Nitzer Ebb (Track 11 from the album: Belief) What's This?
 
Old January 27th, 2005, 05:54 PM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why is it not recommended? I thought is supported both to give the programmer the ability to use either? Are you saying it's just getting outdated and makes the programming harder or limites your choices in something. Or is it more of a preference in keeping with the most updated version of what you can do with your code and how to do it?

I just don't see how it would add functionality to what I was after. Maybe your saying it would become manditory if I had needed to add more functionality to the page? If you have time to respond to this that would be cool just for my future reference. But it sounds like something that will become evident as time passes programming in asp.net.

Also I'm curious what ASP.NET does that PHP doesn't. I have a programmer friend that is hassling me to try it "it's the newest best blah blah blah, thing you ever blah blah blah" Good grief I have never heard that about open source before.

 
Old January 27th, 2005, 06:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Like I said in my previous page, if gives you compile time error checking, intelli sense and strongly typed objects.

The error you had would never have occurred when you had use ASPX controls. You would have a compile time error if you declared RecommendToken and then tried to access txtRecommendToken.Text.

Also, when you type txtRecommendToken. a list with methods and properties for the text box controls appears which makes it much easier to see what you're working with and what it can do.

Most controls provide a similar way to work with; so once you understand what to do with a textBox it's easier to work with other controls that don't have an Html control counterpart.

By using ASP controls, you really take advantage of the ASP.NET Framework. In most applications I built in .NET I never needed the Html controls.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Hot Pants Explosion by The B-52's (Track 2 from the album: Good Stuff) What's This?









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