locked
Insert cannot seem to find textbox for parameter value RRS feed

  • Question

  • User-754876135 posted
    Hi all
    I am convinced this must be a common problem, but I cannot seem to find a reference to it. I have a simple contact information database. I add a SQLDataSource to my page and configure the insert using the Wizard. I make NO other changes, but when I run the page and try to test the insert, it fails claiming one of the parameters is a null value. My web code has the textbox as a required field, and there is definitely data in it. Yet the SQL insert cannot seem to get that data.
    Here is the SQLDataSource code as generated by the VWD 2010 SQLDataSource Wizard:
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BASProspect %>" DeleteCommand="DELETE FROM [ProspectInfo] WHERE [PNum] = @PNum" InsertCommand="INSERT INTO [ProspectInfo] ([FName], [LName], [Email], [BusName], [BusDesc], [Comments], [AreaCode], [Phone], [Extension], [PreferEmail], [PreferPhone]) VALUES (@FName, @LName, @Email, @BusName, @BusDesc, @Comments, @AreaCode, @Phone, @Extension, @PreferEmail, @PreferPhone)" SelectCommand="SELECT * FROM [ProspectInfo]" UpdateCommand="UPDATE [ProspectInfo] SET [FName] = @FName, [LName] = @LName, [Email] = @Email, [BusName] = @BusName, [BusDesc] = @BusDesc, [Comments] = @Comments, [AreaCode] = @AreaCode, [Phone] = @Phone, [Extension] = @Extension, [PreferEmail] = @PreferEmail, [PreferPhone] = @PreferPhone WHERE [PNum] = @PNum"> <DeleteParameters> <asp:Parameter Name="PNum" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="FName" Type="String" /> <asp:Parameter Name="LName" Type="String" /> <asp:Parameter Name="Email" Type="String" /> <asp:Parameter Name="BusName" Type="String" /> <asp:Parameter Name="BusDesc" Type="String" /> <asp:Parameter Name="Comments" Type="String" /> <asp:Parameter Name="AreaCode" Type="String" /> <asp:Parameter Name="Phone" Type="String" /> <asp:Parameter Name="Extension" Type="String" /> <asp:Parameter Name="PreferEmail" Type="Boolean" /> <asp:Parameter Name="PreferPhone" Type="Boolean" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="FName" Type="String" /> <asp:Parameter Name="LName" Type="String" /> <asp:Parameter Name="Email" Type="String" /> <asp:Parameter Name="BusName" Type="String" /> <asp:Parameter Name="BusDesc" Type="String" /> <asp:Parameter Name="Comments" Type="String" /> <asp:Parameter Name="AreaCode" Type="String" /> <asp:Parameter Name="Phone" Type="String" /> <asp:Parameter Name="Extension" Type="String" /> <asp:Parameter Name="PreferEmail" Type="Boolean" /> <asp:Parameter Name="PreferPhone" Type="Boolean" /> <asp:Parameter Name="PNum" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource>
    And here are the three "required" text boxes.
        <table>
            <tr>
                
                <td>
                    <table>
                        <tr>
                            <td style="width: 300px;">
                                <b>First Name</b>&nbsp;<small>(max 25 characters, required)&nbsp;
                                <asp:RequiredFieldValidator ID="FNameValidator" runat="server" ErrorMessage="Required!"
                                    ControlToValidate="FName" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator></small>
                                <asp:TextBox ID="FName" runat="server" Width="275px" MaxLength="25">
                                </asp:TextBox>
                            </td>
                            <td style="width: 300px;">
                            <b>Last Name</b>&nbsp;<small>(max 25 characters, required)&nbsp;
                                <asp:RequiredFieldValidator ID="LNameValidator" runat="server" ErrorMessage="Required!"
                                    ControlToValidate="LName" Font-Bold="True" ForeColor="Red">
                                </asp:RequiredFieldValidator></small>
                                <asp:TextBox ID="LName" runat="server" Width="275px" MaxLength="25">
                                </asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </td>
                <td style="width: 350px; padding-left: 15px">
                <b>Email Address</b>&nbsp; <small>(required)&nbsp;
                    <asp:RequiredFieldValidator ID="EmailValidator" runat="server" ErrorMessage="Required!"
                        ControlToValidate="Email" Font-Bold="True" ForeColor="Red">
                    </asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="EmailExpressionValidator" runat="server" ErrorMessage="Invalid email address!"
                        ControlToValidate="Email" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Font-Bold="True" ForeColor="Red">
                    </asp:RegularExpressionValidator></small>
                    <br />
                    <asp:TextBox ID="Email" runat="server" Width="300px" MaxLength="100"></asp:TextBox>
                </td>
            </tr>
    So why does the datasource parameter not find the data for the insert?
    Thanks
    Richard
     
    Friday, March 25, 2011 7:19 PM

All replies

  • User1983249378 posted

    click on configure datasource > advance then check on both check options in advace generation options in order to insert update , delete via sqldatasource

    Saturday, March 26, 2011 1:25 AM
  • User77042963 posted

    You can hook your SqlDataSource to a datacontrol for test INSERT function. For example, FormView or DetailsView.  Or you need to use ControlParameter to link your TextBox to get the value for the InsertParameter.

    Saturday, March 26, 2011 10:33 PM