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...