How could I retrieve the number of affected row within SqlDataSource.inserted RRS feed

  • Question

  • User1700504264 posted


    I am using SqlDataSource to insert a record, this is the markup

    <asp:SqlDataSource ID="TraineeSqlDataSource" runat="server"
                                        ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
                                        InsertCommand=" IF NOT EXISTS (SELECT Contact FROM Trainee WHERE Contact=@contact)
                                        INSERT INTO Trainee (Contact, IDType, IDNumber, Education, gainedPoints, rate) 
                                        VALUES (@Contact, @idtype, @idnumber, @education, @gainedpoints, @rate)
                                            <asp:parameter Name="Contact" type="Int64" />
                                            <asp:ControlParameter ControlID="ddlIDType" Name="idtype" PropertyName="SelectedValue" />
                                            <asp:ControlParameter ControlID="txtIDNumber" Name="idnumber" PropertyName="Text" />
                                            <asp:ControlParameter ControlID="ddlDegree" Name="education" PropertyName="SelectedValue" />
                                            <asp:Parameter Name="gainedpoints" Type="Int64" DefaultValue="0" />
                                            <asp:Parameter Name="rate" Type="Int16" DefaultValue="0" />

    in the code behind I use this code to insert a new record

    TraineeSqlDataSource.InsertParameters("Contact").DefaultValue = cid

    I need to do two things in the TraineeSqlDataSource.inserted event

    1. I need to check if a row is inserted or not?
    2. I need to call a function and pass the (cid) value to it, how could I access the (cid) value?

    May you please help me how to do this?

    Thank you

    Monday, April 23, 2018 3:26 PM

All replies