Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 February 28th, 2007, 08:13 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default ERROR: Procedure or Function 'x' expects paramater

Not sure why I didn't discover this earlier, but I am trying to update my Database using a storedprocedure and I get an error:

Procedure or Function 'updateMember' expects parameter '@councilPosition', which was not supplied.

"CouncilPosition" is a nullable field, however.

How do I fix this?

Thanks,
Rob

 
Old February 28th, 2007, 08:27 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Even if its a nullable field, you have to at least pass NULL into it through the framework. Although I do not know the reason for this.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old February 28th, 2007, 08:34 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Thank you for the quick reply---but how do I get the ObjectDataSource to pass a NULL if the value is empty?

Thanks,
Rob

 
Old February 28th, 2007, 08:48 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Unforunately, I can't answer that. While the ObjectDataSource is a great control I still do alot of my database transactions through Paramertized queries and stored procedures that I execute using datareaders and such. However, this post may be of some help to you.

http://msdn2.microsoft.com/en-us/library/aa581779.aspx

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old February 28th, 2007, 09:08 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Not really..lol.

I do the same thing--I pass my Gridview Labels through an ObjectDataSource parameter into my own class that has a parameter

Dim knightsDBConn As New SqlConnection(conString)


        Dim sqlString As String = "updateMember"
        Dim sqlCmd As New SqlCommand(sqlString, knightsDBConn)
        sqlCmd.CommandType = CommandType.StoredProcedure
        sqlCmd.Parameters.AddWithValue("@userName", userName)
        sqlCmd.Parameters.AddWithValue("@email", email)
        sqlCmd.Parameters.AddWithValue("@address", address)
        sqlCmd.Parameters.AddWithValue("@city", city)
        sqlCmd.Parameters.AddWithValue("@state", state)
        sqlCmd.Parameters.AddWithValue("@zip", zip)
        sqlCmd.Parameters.AddWithValue("@home_phone", home_phone)
        sqlCmd.Parameters.AddWithValue("@cell_phone", cell_phone)
        sqlCmd.Parameters.AddWithValue("@password", password)
        sqlCmd.Parameters.AddWithValue("@councilPosition", councilPosition)

        knightsDBConn.Open()
        sqlCmd.ExecuteNonQuery()
        sqlCmd = Nothing

My problem is how to pass something in "councilPosition" when it is an empty string.

-Rob

 
Old February 28th, 2007, 09:16 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

As Holmes said to Watson "Thats elementary"!

This is quite like how I do things within my applications so you can try one of 2 things:
1.

If councilPosition.Trim() = "" Then councilPosition = "Null"

2.
If councilPosition.Trim() = "" Then
     sqlCmd.Parameters.AddWithValue("@councilPosition", DBNull)
Else
     sqlCmd.Parameters.AddWithValue("@councilPosition", councilPosition)
End If

In this case DBNull is a type and the Parameter *should* allow you to pass it in.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 1st, 2007, 01:26 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

I'll try again, but what happened is it either (since councilPosition is a string) gave the "string" value as "null" when I tried simply "null"..when I tried passing system.DBNull it said it could not be passed as a parameter (or something like that).

-Rob

 
Old March 3rd, 2007, 07:02 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Instead of passing DBNull, you should pass DBNull.Value.

As you discovered, setting it to a string of "null" will pass the literal value of the word null to the database, which is not what you want.

Instead:

If Not String.IsNullOrEmpty(councilPosition) AndAlso councilPosition.Trim() IsNot String.Empty Then
  sqlCmd.Parameters.AddWithValue("@councilPosition", councilPosition)
Else
  sqlCmd.Parameters.AddWithValue("@councilPosition", DBNull.Value)
End If

This code first checks if the string is already null or an empty string. If it isn't, it then calls Trim to see if it's String.Empty after trimming. If that isn't the case either, it means it contains a value and it is passed to the database.

Otherwise, DBNull.Value is passed which represents a null value in the database.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Function Procedure reneemettrie Excel VBA 0 June 13th, 2008 11:06 AM
Codeplot expects NCName why? djones425 BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 0 March 3rd, 2008 01:11 AM
Function and Procedure code_lover Oracle 2 July 24th, 2007 07:05 AM
Maximum stored procedure, function, tirgger error kuku SQL Server 2000 1 November 7th, 2005 03:04 AM
Parameter Expects sureshbabu Classic ASP Databases 15 September 17th, 2004 03:14 AM





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