Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 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 July 9th, 2015, 03:58 AM
Authorized User
 
Join Date: Dec 2008
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Default Chapter 15, page 555, Hooking into RowDataBound

I actually took this just as an example because it is a good example of how messy it gets. Here's the code:

Code:
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" 
      DeleteCommand="DELETE FROM [Genre] WHERE [Id] = @Id" 
      InsertCommand="INSERT INTO [Genre] ([Name], [SortOrder]) VALUES (@Name, @SortOrder)" 
      ProviderName="<%$ ConnectionStrings:PlanetWroxConnectionString1.ProviderName %>" 
      SelectCommand="SELECT Genre.Id, Genre.Name, Genre.SortOrder, COUNT(Review.Id) AS NumberOfReviews 
                     FROM Genre 
                     LEFT OUTER JOIN Review ON Genre.Id = Review.GenreId 
                     GROUP BY Genre.Id, Genre.Name, Genre.SortOrder" 
      UpdateCommand="UPDATE [Genre] SET [Name] = @Name, [SortOrder] = @SortOrder WHERE [Id] = @Id">
Is there any way to use variables in these? For example, to make this look like:

Code:
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString=ConnString 
      DeleteCommand=DelComm
      InsertCommand=InsComm 
      ProviderName=ProvName
      SelectCommand=SelComm
      UpdateCommand=UpdComm>
and then declare those variables (ConnString, DelComm, etc.) somewhere, like in the code behind or some configuration file? Would make it _a lot_ less messy. I do understand that in the book the examples are the way they are, but given that they are only book examples (that is, "show what it does with least possible code"), in real-world those would get even more messy.

I have kind of a feeling I should know the answer already being this far in the book...
 
Old July 10th, 2015, 03:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, it can get messy quickly ;-) You could set them in Code Behind:

SqlDataSource1.SelectCommand = "..."

but that's equally messy.

A much better solution is to use EF and LINQ, as explained later in the book.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Jaymond Flurrie (July 10th, 2015)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 19, Page 555, Turning off unobtrusive validation Drogil BOOK: Beginning Visual C# 2012 0 November 18th, 2013 03:33 PM
page 555, step 2 properties dialogue is not shown sophia BOOK: Beginning Visual C# 2010 1 July 18th, 2012 11:49 PM
Chapter 15 page 473 dampyr BOOK: Beginning Visual C# 2010 2 December 15th, 2011 05:03 AM
Try It Out Page 555 jlransford BOOK: Beginning ASP.NET 4 : in C# and VB 5 September 11th, 2010 04:02 PM
Chapter 15 Page 711 JOHNW BOOK: Beginning ASP 3.0 3 January 14th, 2004 11:14 AM





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