locked
SQLDATASOURCE Insert not working RRS feed

  • Question

  • User-883855585 posted

    I have the following SqlDataSource that has an insert statement that is not working correctly

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" InsertCommand="insert into census_staffing (unit, planned_discharges, one_to_one, rn, lpn, techs,
    usp, sitter, cmt, telesit, orientee, t_date, isolations, notes)
    values(@unit, @disc, @one, @rn, @lpn, @techs, @usp, @sitter, @cmt, @telesit, @orientee, getdate(),
    @iso, @notes)" SelectCommand=" 
    select  
    isnull(rn,0) RN, isnull(lpn,0) LPN, isnull(techs,0) Tech,
    isnull(usp,0) USP, isnull(sitter,0) Sitter, isnull(cmt,0) CMT, isnull(telesit,0) Tele,
    ISNULL(isolations,0) Isolations, Notes , isnull(planned_discharges,0) Disc,
    ISNULL(orientee,0) Orientee,
    ISNULL(one_to_one,0) OneOnOne ,convert(varchar,t_date,101)+ ' ' +convert(varchar(10),t_date,108) LastUpdate
    from
    census_staffing 
    where
    unit = 'T2'
    and t_date = (select MAX(t_date) from census_staffing where unit = 'T2') ">
            <InsertParameters>
                <asp:ControlParameter ControlID="Label38" Name="unit" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox1" Name="disc" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox2" Name="one" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox4" Name="rn" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox5" Name="lpn" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox25" Name="techs" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox7" Name="usp" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox26" Name="sitter" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox28" Name="cmt" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox29" Name="telesit" 
                    PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox30" Name="orientee" 
                    PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox31" Name="iso" PropertyName="Text" />
                <asp:ControlParameter ControlID="TextBox32" Name="notes" PropertyName="Text" />
            </InsertParameters>
        </asp:SqlDataSource>

    There are multiple textboxes that are populated on form load.  The user can change the existing values and click the save button to insert a new row.  When the insert runs, it is inserting the values in the textboxes when the form originally loads.  it does not recognize the newly entered values.  the insert is called with a button click:

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
    
            SqlDataSource2.Insert()
            ClearTextBox(Me)
            TextBox1.Focus()
    
        End Sub


     It appears to be a timing issue but not sure.

    thanks 

    Thursday, February 1, 2018 5:02 PM

Answers

  • User-883855585 posted

    added postback check in page load event that populates textboxes.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 1, 2018 6:07 PM