我遵循了SqlDataSource.Insert方法,但一直无法使其正常工作。这是一个DOT net 4.5 Web表单应用程序。我的数据库显示已添加记录但没有数据传输到记录。这是代码:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master"CodeBehind="TimeLog.aspx.cs" Inherits="Goings_on.TimeLog" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:Panel ID="Panel1" runat="server" BackColor="#EDE174" BorderWidth="5px" BorderColor="#00CC00">
<div class="form-group">
<div class="col-sm-offset-1 col-sm-11">
<asp:Label ID="Label6" runat="server" Text="Employee Id"></asp:Label>
<br/>
<asp:TextBox ID="EmpId" runat="server" Width="147px"></asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator1"
runat="server"
ControlToValidate="EmpId"
Display="Static"
ErrorMessage="Please enter Employee ID."/>
<br/>
<asp:Label ID="Label5" runat="server" Text="Type Of Route"></asp:Label>
<br/>
<asp:DropDownList ID="TypeOfRoute" runat="server" BackColor="White" Width="125px" Height="35px" DataValueField="Id_Type" ToolTip="Please indicate the route type!">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Regular</asp:ListItem>
<asp:ListItem>Homeless</asp:ListItem>
<asp:ListItem>Special</asp:ListItem>
<asp:ListItem>Field Trip</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator
id="RequiredFieldValidator2"
runat="server"
ControlToValidate="TypeOfRoute"
Display="Static"
ErrorMessage="Please enter type of route."/>
<br/>
<asp:TextBox ID="GetDate" runat="server" Height="35px" Width="177px" BorderColor="Yellow" Font-Size="Small" BackColor="White"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/image/CalendarIcon.png" OnClick="ImageButton1_Click1" Height="35px" ImageAlign="AbsBottom"/>
</div>
<div class="col-sm-offset-1 col-sm-11">
<asp:Calendar ID="Calendar1" runat="server" SelectionMode="Day"
BackColor="White" BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="10pt" ForeColor="#003399" Height="225" Width="225" OnDayRender="AttachHolidays" OnSelectionChanged="Calendar1_SelectionChanged">
<DayHeaderStyle BackColor="#00CC00" ForeColor="#336666" Height="1px"/>
<NextPrevStyle Font-Size="10pt" ForeColor="#CCCCFF"/>
<OtherMonthDayStyle ForeColor="#999999"/>
<SelectedDayStyle BackColor="#66FFFF" Font-Bold="True" ForeColor="#CCFF99"/>
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666"/>
<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px"/>
<TodayDayStyle BackColor="#CCFF33" ForeColor="White"/>
<WeekendDayStyle BackColor="#CCCCFF"/>
</asp:Calendar>
</div>
<div class="col-sm-offset-1 col-sm-11">
<asp:Button ID="AmButton" runat="server" Text="AM Route" Width="225px" Height="35px" OnClick="AmButton_Click"/>
</div>
<div class="col-sm-offset-1 col-sm-11">
<asp:Label ID="Label1" runat="server" Text="AM Hour_Min In" Width="225px"></asp:Label>
<br/>
<div>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource10" DataTextField="AMhour" DataValueField="AMhour" Width="80px" BackColor="White" Height="20px">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource10" DataTextField="AMminutes" DataValueField="AMminutes" Width="80px" BackColor="White" Height="20px">
</asp:DropDownList>
</div>
</div>
</div>
<div class="col-sm-offset-1 col-sm-11">
<asp:Label ID="SubmitInfo"
runat="server"
Text="SubmittedInfo">
</asp:Label>
<asp:SqlDataSource
ID="SqlDataSource10"
runat="server"
connectionstring="<%$ ConnectionStrings:Goings_OnConnectionString %>"
SelectCommand="SELECT AMminutes, AMhour FROM ClockTime"
InsertCommand="INSERT INTO DayClockTime (Id_Employee, Id_Type, Id_Date, AmHoOut, AmMinOut) VALUES (@EmpId, @TypeOfRoute , @GetDate, @AmHoO, @AmMinO)">
<insertparameters>
<asp:FormParameter Name="EmpId" FormField="EmpId"/>
<asp:FormParameter Name="TypeOfRoute" FormField="TypeOfRoute"/>
<asp:FormParameter Name="GetDate" FormField="GetDate"/>
<asp:FormParameter Name="AmHoO" FormField="DropDownList1"/>
<asp:FormParameter Name="AmMinO" FormField="DropDownList2"/>
</insertparameters>
</asp:SqlDataSource>
<br/>
<asp:Button ID="TimeSubmit"
runat="server"
OnClick="TimeSubmit_Click"
Text="Insert Clock Time"
Width="163px"/>
</div>
<p>
</p>
</asp:Panel>
</asp:Content>
protected void TimeSubmit_Click(object sender, EventArgs e)
{
SqlDataSource10.Insert();
}