[英]CommandName issues to insert to a database
在下面的代码中,当我们定义参数CommandName =“ Insert”时,它实际上与执行方法Insert相同吗? 由于我在任何地方都找不到插入...
<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>
我也有以下SqlDataSource:
<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>
我希望它使用InsertCommand进行插入,但是当我执行SqlDataSource1.Insert()时,它抱怨开始时间为NULL
由于错误是由于未设置开始时间值,因此该错误可能与您用于获取开始时间值的字段有关。 您使用的是Bind(“ starttime”)而不是Eval(“ starttime”)吗?
Bind("starttime")
更新:您正在设置参数吗? 如果不是,您应该告诉SqlDataSource在哪里获取它。
<asp:ControlParameter Name="starttime" ControlID="dtpicker"
PropertyName="startDateTime" Type="DateTime" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.