Gridview: What happened to nTier architecture?

R

Richard Coltrane

Hello

Im reading this article about the Gridview:

http://msdn.microsoft.com/msdnmag/issues/04/08/GridView/

Whilst I realise that im not forced to use their methods I do find it
confusing that the article states that the code below is an example of the
"recommended data binding approach in ASP 2.0".
Why is placing DAL level code and connection strings on every page that uses
data from a data store now the "recommended approach"?

The idea seems completely stupid on every level.

Richard


<%@ Page theme="SmokeAndGlass" %>
<html>
<head runat="server" />
<body>
<form runat="server">
<asp:TextBox runat="server" ID="EmpID" Text="3" />
<asp:button runat="server" Text="Refresh" />

<asp:SqlDataSource runat="server" ID="MySource"
ConnectionString="SERVER=(local);DATABASE=northwind;Integrated
Security=SSPI;"
DataSourceMode="DataSet"
SelectCommand="SELECT firstname, lastname FROM employees WHERE
employeeid > @MinID">
<SelectParameters>
<asp:ControlParameter Name="MinID" ControlId="EmpID"
PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>

<asp:GridView runat="server" ID="grid"
DataSourceId="MySource"
AutoGenerateColumns="true">
</asp:GridView>
</form>
</body>
</html>
 
K

Kevin Frey

I think SqlDataSource has received a lot of criticism exactly for the
reasons you mention.

It seems to me that ObjectDataSource and/or building your own Data Source
are the way to go, in order to maintain a degree of isolation between the
presentation layer, business logic, and data access.
 
M

Mark Fitzpatrick

Richard,
I've never used this method myself and I've never found a need to. I
believe it is essentially an opinion on the topic as opposed to canon. Also,
keep in mind that this article was written a year before ASP.Net 2.0 came
out, so it's not entirely accurate as it was written with beta code, and
also the thinking at the time of the beta. Whenever I wonder about a best
approach, I typically refer to the various patterns and practices guides
that MS puts out. These tend to have the best concepts and tips for
architecting some of this stuff that most magazine articles.
 
J

Jay Pondy

For very small projects the SQL Datasource can save a lot of time. To solve
some of the shortcomings you mentioned I use this approach:

<asp:SqlDataSource ID="dsTips" runat="server" ConnectionString="<%$
ConnectionStrings:HRConnectionString %>" SelectCommand="jpTipsFetch"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:parameter Direction="ReturnValue" Name="RETURN_VALUE"
Type="Int32" />
<asp:FormParameter FormField="txtPKID" Name="PKID" Type="Int32"
/>
<asp:FormParameter FormField="cboDepartment"
Name="DepartmentName" Type="String" />
<asp:FormParameter DefaultValue="" FormField="cboEmployee"
Name="EmployeeName" Type="String" />
<asp:FormParameter DefaultValue="" FormField="cboSupervisor"
Name="SupervisorName" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

After you get the hang of it it can save you a lot of time, but again, on
relatively small projects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top