Wrox Programmer Forums
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 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 August 18th, 2009, 05:03 PM
Authorized User
Join Date: Aug 2009
Posts: 12
Thanks: 5
Thanked 0 Times in 0 Posts
Default Comments AddedByIP


I have not been able to find this addressed anywhere so that is why I am posting a new thread.

In the database table this field is defined to be nchar(15). The parameter @AddedByIP in the tbh_Articles_InsertComment stored procedure is consequently also defined to be nchar(15). In the downloaded code this is the implementation of the InsertComment method in the SqlArticlesProvider class:

      public override int InsertComment(CommentDetails comment)
         using (SqlConnection cn = new SqlConnection(this.ConnectionString))
            SqlCommand cmd = new SqlCommand("tbh_Articles_InsertComment", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@AddedDate", SqlDbType.DateTime).Value = comment.AddedDate;
            cmd.Parameters.Add("@AddedBy", SqlDbType.NVarChar).Value = comment.AddedBy;
            cmd.Parameters.Add("@AddedByEmail", SqlDbType.NVarChar).Value = comment.AddedByEmail;
            cmd.Parameters.Add("@AddedByIP", SqlDbType.NVarChar).Value = comment.AddedByIP;
            cmd.Parameters.Add("@ArticleID", SqlDbType.Int).Value = comment.ArticleID;
            cmd.Parameters.Add("@Body", SqlDbType.NVarChar).Value = comment.Body;
            cmd.Parameters.Add("@CommentID", SqlDbType.Int).Direction = ParameterDirection.Output;
            int ret = ExecuteNonQuery(cmd);
            return (int)cmd.Parameters["@CommentID"].Value;
Note how in the code the parameter @AddedByIP is defined to be nvarchar. I assume that the site is working fine like that, so I am assuming that there will be a conversion going on in SQL Server 2005. Wouldn't this conversion reduce performance?

Thanks for any clarification on this matter.
Old August 19th, 2009, 03:46 PM
Lee Dumond's Avatar
Wrox Author
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts

Yes, this is probably an oversight by the author (wouldn't be the only one!).

There is an implicit conversion that takes place, but I doubt it affects performance much if at all. When populating an nchar, SQL Server merely pads the input string to take up a fixed length in storage, if the input string is shorter than the nchar limit (in this case, 15 characters).
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

if (this.PostHelpedYou)
The Following User Says Thank You to Lee Dumond For This Useful Post:
alfinmass (August 19th, 2009)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Comments in one go Pankaj C XSLT 3 September 9th, 2007 07:05 AM
preapprove comments thuyvncr BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 July 9th, 2007 01:23 AM
Questions, Comments shane.perran BOOK: Beginning SharePoint 2007: Building Team Solutions with MOSS 2007 ISBN: 978-0-470-12449-9 0 May 31st, 2007 05:55 PM
Comments janees ASP.NET 1.0 and 1.1 Professional 1 April 8th, 2007 09:27 PM
Approving comments ceadge PHP Databases 2 October 23rd, 2006 07:07 AM

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