SqlDataSource and programatic access?

A

ayende

I've the following scenario, a web page that dispaly a GridView using
SqlDataSource define thus:

<asp:SqlDataSource ID="BoardTypes" runat="server" ConnectionString='<%$
ConnectionStrings:ConnectionString %>'
SelectCommand="SELECT BoardTypes.BoardTypeId,
BoardTypes.BoardTypeName, BoardTypes.BoardTypeDescription,
BoardTypes.ValidityEndDate, BoardTypes.ValidityStartDate,
OrganizationUnit.Name AS OrganizationalUnitName FROM BoardTypes INNER
JOIN OrganizationUnit ON OrganizationUnit.Id =
BoardTypes.OrganizationalUnitId WHERE (BoardTypes.IsCancelled =
@IsCancelled)"
InsertCommand="INSERT INTO BoardTypes(BoardTypeName,
BoardTypeDescription, ValidityStartDate, ValidityEndDate,
OrganizationalUnitId, IsCancelled) VALUES (@BoardTypeName,
@BoardTypeDescription, @ValidityStartDate, @ValidityEndDate,
@OrganizationalUnitId, 0)">
<SelectParameters>
<asp:parameter DefaultValue="false" Name="IsCancelled"
Type="Boolean" />
</SelectParameters>
<InsertParameters>
<asp:parameter Name="BoardTypeName" Type="string" />
<asp:parameter Name="BoardTypeDescription" Type="string"/>
<asp:parameter Name="ValidityStartDate" Type="datetime" />
<asp:parameter Name="ValidityEndDate" Type="datetime"/>
<asp:parameter Name="OrganizationalUnitId" Type="string"/>
</InsertParameters>
</asp:SqlDataSource>

I've a form that collects information about a new row and then post it
to the server. What I want to do is to take the values from the form
plus several other values that I get elsewhere, and insert them to the
database programmatically.

It's a dumb question, but I googled and looked in the help, and I can't
find the way to do it.

How do I pass the correct parameters? I tried InsertParameters.Add(),
but they already exist.


Another question:
Is it possible to create a page/file where I will declare all the data
sources? My goal is to be able to reuse a data source on several
classes, I can't see an immediate way to do it, though.
 
A

Ayende Rahien

a) I want to learn how to do it this way.
b) It's a very quick way to develop the UI and the bussiness logic where
the database layer is still yet to be implemented (depends on other
factors that I can't control right now). I want the lowest friction
possible so I can refactor later if needed.


c) I wonder if I can somehow group SqlDataSources togheter, which would
enable me to use them as the data layer.
 

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

Top