SqlDataSource and programatic access?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.

.



Relevant Pages

  • Re: SqlDataSource and programatic access?
    ... rather than the dragdrop SqlDataSource approach? ... > OrganizationUnit.Name AS OrganizationalUnitName FROM BoardTypes INNER ... My goal is to be able to reuse a data source on several ...
    (microsoft.public.dotnet.framework.adonet)
  • SqlDataSource and programatic access?
    ... OrganizationUnit.Name AS OrganizationalUnitName FROM BoardTypes INNER ... It's a dumb question, but I googled and looked in the help, and I can't ... My goal is to be able to reuse a data source on several ...
    (microsoft.public.dotnet.framework.adonet)
  • SqlDataSource and programatic access?
    ... OrganizationUnit.Name AS OrganizationalUnitName FROM BoardTypes INNER ... It's a dumb question, but I googled and looked in the help, and I can't ... My goal is to be able to reuse a data source on several ...
    (microsoft.public.dotnet.framework.adonet)