Dobrý den, načítám do DropDownListu data z jedné realce, které pak ukládám do druhé relace. Data se do DropDownListu úspěšně načtou, ale když pak ve vkládacím formuláři vyberu hodnotu a chci ji uložit do jiné tabulky vyhodí to chybu: Cannot insert the value NULL into column 'StateId', table 'TaskOrganizerDB.dbo.Requests'; column does not allow nulls. INSERT fails. Zde je zdrojový kód:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>
<script runat="server">
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TaskOrganizerDBConnectionString %>"
DeleteCommand="DELETE FROM [Requests] WHERE [RequestId] = @RequestId"
InsertCommand="INSERT INTO [Requests] ([Title], [Description], [DateCreated], [DateExpiration], [CreatedBy], [StateId]) VALUES (@Title, @Description, @DateCreated, @DateExpiration, @CreatedBy, @StateId)"
SelectCommand="SELECT * FROM [Requests] WHERE ([RequestId] = @RequestId)"
UpdateCommand="UPDATE [Requests] SET [Title] = @Title, [Description] = @Description, [DateCreated] = @DateCreated, [DateExpiration] = @DateExpiration, [CreatedBy] = @CreatedBy, [StateId] = @StateId WHERE [RequestId] = @RequestId">
<SelectParameters>
<asp:QueryStringParameter Name="RequestId" QueryStringField="id" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="RequestId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="DateCreated" Type="DateTime" />
<asp:Parameter Name="DateExpiration" Type="DateTime" />
<asp:Parameter Name="CreatedBy" Type="Int32" />
<asp:Parameter Name="StateId" Type="Int32" />
<asp:Parameter Name="RequestId" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="DateCreated" Type="DateTime" />
<asp:Parameter Name="DateExpiration" Type="DateTime" />
<asp:Parameter Name="CreatedBy" Type="Int32" />
<asp:Parameter Name="StateId" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsState" runat="server"
ConnectionString="<%$ ConnectionStrings:TaskOrganizerDBConnectionString2 %>"
SelectCommand="SELECT StateId AS StateID, State FROM States">
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="RequestId"
DataSourceID="SqlDataSource1" DefaultMode="Insert">
<EditItemTemplate>
RequestId:
<asp:Label ID="RequestIdLabel1" runat="server"
Text='<%# Eval("RequestId") %>' />
<br />
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />
DateCreated:
<asp:TextBox ID="DateCreatedTextBox" runat="server"
Text='<%# Bind("DateCreated") %>' />
<br />
DateExpiration:
<asp:TextBox ID="DateExpirationTextBox" runat="server"
Text='<%# Bind("DateExpiration") %>' />
<br />
CreatedBy:
<asp:TextBox ID="CreatedByTextBox" runat="server"
Text='<%# Bind("CreatedBy") %>' />
<br />
StateId:
<asp:TextBox ID="StateIdTextBox" runat="server" Text='<%# Bind("StateId") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td>Titulek: </td>
<td><asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' /></td>
</tr>
<tr>
<td>Popis: </td>
<td><asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' /></td>
</tr>
<tr>
<td>Datum ukončení: </td>
<td><asp:TextBox ID="DateExpirationTextBox" runat="server" Text='<%# Bind("DateExpiration") %>' /></td>
</tr>
<tr>
<td>Vytvořeno: </td>
<td><asp:TextBox ID="CreatedByTextBox" runat="server" Text='<%# Bind("CreatedBy") %>' /></td>
</tr>
<tr>
<td>Stav: </td>
<td>
<asp:DropDownList ID="ddlState" runat="server" DataSourceID="sdsState" DataTextField="State"
DataValueField="StateID" SelectedValue='<%# Bind("StateId") %>' >
</asp:DropDownList>
</td>
<!--<td><asp:TextBox ID="StateIdTextBox" runat="server" Text='<%# Bind("StateId") %>' /></td>-->
</tr>
<tr>
<td>Vypracovává: </td>
<td><asp:TextBox ID="UserIdTextBox" runat="server" Text='<%# Bind("UserId") %>' /></td>
</tr>
</table>
<asp:Button ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Vložit" />
<asp:Button ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Zrušit" />
</InsertItemTemplate>
</asp:FormView>
</asp:Content>
|