CommandName issues to insert to a database

Posted by Alexander on Stack Overflow See other posts from Stack Overflow or by Alexander
Published on 2010-04-05T16:00:05Z Indexed on 2010/04/05 16:03 UTC
Read the original article Hit count: 214

Filed under:
|

In the below code, when we define the parameters CommandName="Insert" is it actually the same as executing the method Insert? As I can't find Insert anywhere...

<div class="actionbuttons">
                        <Club:RolloverButton ID="apply1" CommandName="Insert" Text="Add Event" runat="server" />
                        <Club:RolloverLink ID="Cancel" Text="Cancel" runat="server" NavigateURL='<%# "Events_view.aspx?EventID=" + Convert.ToString(Eval("ID")) %>' />
                    </div>

I have the following SqlDataSource as well:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
    SelectCommand="SELECT dbo.Events.id, dbo.Events.starttime, dbo.events.endtime, dbo.Events.title, dbo.Events.description, dbo.Events.staticURL, dbo.Events.photo,  dbo.Events.location, dbo.Locations.title AS locationname FROM  dbo.Events LEFT OUTER JOIN dbo.Locations ON dbo.Events.location = dbo.Locations.id where Events.id=@id"
    InsertCommand="INSERT INTO Events(starttime, endtime, title, description, staticURL, location, photo) VALUES (@starttime, @endtime,  @title, @description, @staticURL, @location, @photo)"
    UpdateCommand="UPDATE Events SET starttime = @starttime, endtime=@endtime, title = @title, description = @description, staticURL = @staticURL, location = @location, photo = @photo WHERE (id = @id)"
    DeleteCommand="DELETE Events WHERE id=@id" OldValuesParameterFormatString="{0}">
    <SelectParameters>
        <asp:QueryStringParameter Name="id" QueryStringField="ID" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="starttime" Type="DateTime" />
        <asp:Parameter Name="endtime" Type="DateTime" />
        <asp:Parameter Name="title" />
        <asp:Parameter Name="description" />
        <asp:Parameter Name="staticURL" />
        <asp:Parameter Name="location" />
        <asp:Parameter Name="photo" />
        <asp:Parameter Name="id" />
    </UpdateParameters>
    <InsertParameters>
        <asp:Parameter Name="starttime" Type="DateTime" />
        <asp:Parameter Name="endtime" Type="DateTime" />
        <asp:Parameter Name="title" />
        <asp:Parameter Name="description" />
        <asp:Parameter Name="staticURL" />
        <asp:Parameter Name="location" />
        <asp:Parameter Name="photo" />
        <asp:Parameter Name="id" />
    </InsertParameters>
    <DeleteParameters>
        <asp:QueryStringParameter Name="id" QueryStringField="ID" />
    </DeleteParameters>
</asp:SqlDataSource>

I want it to insert using the InsertCommand, however when I do SqlDataSource1.Insert() it's complaining that starttime is NULL

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET