Cannot insert the value NULL into column 'EmailTo', table 'db191165913.dbo191165913.Email'; column does not allow nulls. INSERT fails.
The statement has been terminated
My code is below:
<%@. Page Language="VB" MasterPageFile="~/real_world/realworld_MasterPage.master" AutoEventWireup="false" CodeFile="send_messages.aspx.vb" Inherits="send_messages" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="email_label" runat="server" Visible="False"></asp:Label>
<asp:SqlDataSource ID="emailsend_source" runat="server" ConnectionString="<%$ ConnectionStrings:IMS_DB %>"
DeleteCommand="DELETE FROM WHERE [EmailID] = @.EmailID"
InsertCommand="INSERT INTO ([UserID], [EmailTo], [EmailFrom], [Subject], [Message], [Status], [Reply], [Forward], [UserName], [SentOn], [IP], [BrowserInfo], [DNSInfo]) VALUES (@.UserID, @.EmailTo, @.EmailFrom, @.Subject, @.Message, '@.Status', '@.Reply', '@.Forward', @.UserName, @.SentOn, @.IP, @.BrowserInfo, @.DNSInfo)"
SelectCommand="SELECT * FROM WHERE ([UserID] = @.UserID)"
UpdateCommand="UPDATE SET [UserID] = @.UserID, [EmailTo] = @.EmailTo, [EmailFrom] = @.EmailFrom, [Subject] = @.Subject, [Message] = @.Message, [Status] = @.Status, [Reply] = @.Reply, [Forward] = @.Forward, [UserName] = @.UserName, [BrowserInfo] = @.BrowserInfo, [DNSInfo] = @.DNSInfo WHERE [EmailID] = @.EmailID">
<DeleteParameters>
<asp:Parameter Name="EmailID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserID" />
<asp:Parameter Name="EmailTo" Type="String" />
<asp:Parameter Name="EmailFrom" Type="String" />
<asp:Parameter Name="Subject" Type="String" />
<asp:Parameter Name="Message" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="Reply" Type="String" />
<asp:Parameter Name="Forward" Type="String" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="BrowserInfo" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="email_label" Name="UserID" PropertyName="Text" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="UserID" />
<asp:Parameter Name="EmailTo" Type="String" />
<asp:Parameter Name="EmailFrom" Type="String" />
<asp:Parameter Name="Subject" Type="String" />
<asp:Parameter Name="Message" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="Reply" Type="String" />
<asp:Parameter Name="Forward" Type="String" />
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="IP" Type="String" />
<asp:Parameter Name="SentOn" Type="datetime" />
<asp:Parameter Name="BrowserInfo" Type="String" />
<asp:Parameter Name="DNSInfo" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="username_email" runat="server" ConnectionString="<%$ ConnectionStrings:IMS_DB %>"
SelectCommand="SELECT [UserName] FROM [Membership] ORDER BY [UserName]">
</asp:SqlDataSource>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="You must fill out the following forms:"
ValidationGroup="email_send" />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="EmailID"
DataSourceID="emailsend_source" DefaultMode="Insert" GridLines="None" Height="50px"
Width="125px">
<Fields>
<asp:BoundField DataField="EmailID" HeaderText="EmailID" InsertVisible="False" ReadOnly="True"
SortExpression="EmailID" />
<asp:TemplateField HeaderText="To" SortExpression="EmailTo">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("EmailTo") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="emailsend_source" DataTextField="UserName" SelectedValue='<%# Bind("UserName") %>' AppendDataBoundItems="True" DataValueField="UserName">
<asp:ListItem>-- Receiving User --</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1"
Display="Dynamic" ErrorMessage="Message Receiver (To)" ValidationGroup="email_send"></asp:RequiredFieldValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("EmailTo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="From" SortExpression="EmailFrom">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmailFrom") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:LoginName ID="login_name" runat="server" />
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("EmailFrom") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Subject" SortExpression="Subject">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Subject") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" MaxLength="50" Text='<%# Bind("Subject") %>'
ValidationGroup="send_email"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox3"
Display="Dynamic" ErrorMessage="Subject" ValidationGroup="email_send"></asp:RequiredFieldValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Subject") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Message" SortExpression="Message">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Message") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Columns="40" MaxLength="500" Rows="10"
Text='<%# Bind("Message") %>' TextMode="MultiLine" ValidationGroup="send_mail"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox4"
Display="Dynamic" ErrorMessage="Message" ValidationGroup="email_send"></asp:RequiredFieldValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Message") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField InsertText="Send Message" ShowInsertButton="True" ValidationGroup="email_send" />
</Fields>
</asp:DetailsView>
</asp:Content
What about changing the EmaiTto Parameter to a ControlParameter:
<InsertParameters>
<asp:Parameter Name="UserID" /><asp:Parameter Name="EmailTo" Type="String" />
<asp:ControlParameter ControlID="DetailsView1$DropDownList1" Name="EmailTo" PropertyName="SelectedValue" />
.....
No comments:
Post a Comment