我正在尝试使用存储过程更新gridview,并且我不断收到错误。我正在使用ms sql 2014 Time(7)字段。我已经尝试过所有"修复"在线发现在存储过程中具有与sqldatasource更新参数中相同数量的参数以及其他似乎不起作用的修复。我想知道是否与时间(7)字段有关?
存储过程
@BlockId int,
@AllDay bit,
@AssigerId int,
@EndTime time(7),
@StartTime time(7)
As
Begin
Update Blocks
Set
Allday = @AllDay,
AssigerId = @AssignerId,
EndTime = @EndTime,
StartTime = @StartTime
Where BlockId = @BlockId
ASP
SqlDataSource
<asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AssignConnectionString %>" deletecommand="deleteBlock" DeleteCommandType="StoredProcedure" UpdateCommand="updateBlock" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="BlockId" Type="Int32" />
<asp:Parameter Name="AssignerId" Type="Int32" />
<asp:Parameter Name="AllDay" Type="Boolean" />
<asp:Parameter Name="EndTime" Type="Datetime" />
<asp:Parameter Name="StartTime" Type="DateTime" />
</UpdateParameters>
</asp:SqlDataSource>
VBCode
Protected Sub GridView1_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
Dim ddl As DropDownList = DirectCast(Gridview1.Rows(e.RowIndex).FindControl("Assignerddl"), DropDownList)
Dim ckbx As DropDownList = DirectCast(Gridview1.Rows(e.RowIndex).FindControl("AllDayck"), DropDownList)
Dim editstartddl As DropDownList = DirectCast(Gridview1.Rows(e.RowIndex).FindControl("editStartddl"), DropDownList)
Dim editendddl As DropDownList = DirectCast(Gridview1.Rows(e.RowIndex).FindControl("editEndddl"), DropDownList)
Dim conStr As String = ConfigurationManager.ConnectionStrings("assignConnectionString").ConnectionString
Dim cn As New SqlConnection(conStr)
cn.Open()
Dim updCmd As New SqlCommand("updateBlock", cn)
updCmd.CommandType = CommandType.StoredProcedure
updCmd.Parameters.Add("@BlockId", SqlDbType.Int).Value = Gridview1.Rows(e.RowIndex).Cells(0).Text
updCmd.Parameters.Add("@AllDay", SqlDbType.NVarChar).Value = ckbx.SelectedValue.ToString()
updCmd.Parameters.Add("@AssignerId", SqlDbType.NVarChar).Value = ddl.SelectedValue.ToString()
updCmd.Parameters.Add("@EndTime", SqlDbType.Time).Value = editendddl.SelectedValue.ToString()
updCmd.Parameters.Add("@StartTime", SqlDbType.Time).Value = editstartddl.SelectedValue.ToString()
SqlDataSource1.DataBind()
updCmd.Parameters.Clear()
bindBlocks()
End Sub
Gridview:
<asp:gridview ID="Gridview1" Width="620px" CssClass="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" onrowcancelingedit="GridView1_RowCanceling" OnRowDeleting="GridView1_RowDeleting" OnRowDeleted="GridView1_RowDeleted" OnRowUpdating="GridView1_RowUpdating" OnRowUpdated="GridView1_RowUpdated" GridLines="None" onrowediting="GridView1_RowEditing" DataSourceID="SqlDataSource1" DataKeyNames="BlockId" EmptyDataText="No Blocks For This Day" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField HeaderText="BlockId" DataField="BlockId" ReadOnly="true" visible="false" />
<asp:BoundField HeaderText="AllDay" DataField="AllDay" ReadOnly="true" visible="false" />
<asp:BoundField HeaderText="StartTime" DataField="StartTime" ReadOnly="true" visible="false" />
<asp:BoundField HeaderText="EndTime" DataField="EndTime" ReadOnly="true" visible="false" />
<asp:TemplateField>
<HeaderStyle Width="25px" />
<ItemStyle Width="25px" />
<EditItemTemplate>
<asp:LinkButton ID="LinkButton2" Runat="server" CommandName="Update">Update</asp:LinkButton>
<hr style="width:100%; margin-top:5px;margin-bottom:5px;" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" />
<hr style="width:100%; margin-top:2px;margin-bottom:2px;" />
<asp:Label ID="lbl" runat="server" Text='<%# Eval("RefereeId") %>' Visible="false"></asp:Label>
<asp:Label ID="Label66" Font-Size="small" runat="server" Visible="false" Text='<%# Eval("BlockId")%>'></asp:Label>
<asp:LinkButton ID="LinkButton1" Runat="server" OnClientClick="return confirm('Are you sure you want to delete this block?');" CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Active Blocks" >
<ItemTemplate>
<asp:label id="Label1" runat="server" text='<%# Eval("BlockDate") %>'></asp:label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<EditItemTemplate>
Start Time: <asp:dropdownlist ID="editStartddl" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDataSource1" DataTextField="StartTime2" DataValueField="StartTime2"
SelectedValue='<%# Bind("StartTime2")%>'>
</asp:dropdownlist><br />
End Time: <asp:dropdownlist ID="editEndddl" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDataSource1" DataTextField="EndTime2" DataValueField="EndTime2"
SelectedValue='<%# Bind("EndTime2")%>'>
</asp:dropdownlist>
</EditItemTemplate>
<ItemTemplate>
<asp:label id="Label1rt" runat="server" Text='<%# "Block Start: " + DisplayAs12HourTime(Eval("StartTime")) %>' visible='<%# IIf(Eval("AllDay") = "True", "False", "True") %>'></asp:label><br />
<asp:label id="Label32" runat="server" Text='<%# "Block End: " + DisplayAs12HourTime(Eval("EndTime")) %>' visible='<%# IIf(Eval("AllDay") = "True", "False", "True") %>'></asp:label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Full or Partial" >
<EditItemTemplate>
<asp:DropdownList ID="AllDayck" SelectedValue='<%# Bind("AllDay") %>' runat="server">
<asp:ListItem Value="False">Part Day Block</asp:ListItem>
<asp:ListItem Value="True">Full Day Block</asp:ListItem>
</asp:DropdownList>
</EditItemTemplate>
<ItemTemplate>
<asp:label id="Label11" runat="server" Text='<%# IIf(Eval("AllDay") = "True", "Full Day Block", "Partial Day Block")%>'></asp:label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Group" >
<EditItemTemplate>
<asp:dropdownlist ID="Assignerddl" runat="server" AppendDataBoundItems="true" DataSourceID="SqlDataSource2" DataTextField="CompanyName" DataValueField="AssignerId"
SelectedValue="<%# Bind('AssignerId') %>">
<asp:ListItem Value="0">Block For All Groups</asp:ListItem>
</asp:dropdownlist>
</EditItemTemplate>
<ItemTemplate>
<asp:label id="Label111" runat="server" text='<%# IIf(Eval("AssignerId") = "0", "All Groups", Eval("CompanyName")) %>'></asp:label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
答案 0 :(得分:0)
我在网格视图上更改了绑定到eval,它没有错误。去图......