Click here to Skip to main content
15,883,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Have a DataGrid on a web form which is bound to an ObjectDataSource. Update, Delete and Retrieve operations all work fine. I cannot, however, find any way to create a new record.

I have tried simply putting text boxes on the screen to accept values for the new record and providing a 'Create' button, but when I get into the event handler and manually call Insert() on the ObjectDataSource, it says the parameters collection is empty. This is despite the fact that I have the following in my .aspx file:

XML
<asp:objectdatasource id="ods" runat="server" typename="TYPENAME_HERE" dataobjecttypename="BLL_OBJECT_NAME" insertmethod="InsertCharacter" selectmethod="RetrieveAllCharacters"
    updatemethod="UpdateCharacter" deletemethod="DeleteCharacter">
    <insertparameters>
        <asp:controlparameter name="FirstName" controlid="newFirstName" propertyname="Text" />
        <asp:controlparameter name="LastName" controlid="newLastName" propertyname="Text" />
        <asp:controlparameter name="Gender" controlid="newGender" propertyname="Text" />
    </insertparameters>
</asp:objectdatasource>


I just can't find any way to get this working, despite reading everything I can find on this subject. Does anyone know how to do this or any way to get a new record created in a database via an ObjectDataSource?

Kind wishes ~ Patrick
Posted

1 solution

I have found a workaround for this. I can't get any automatic databinding to work, but I can insert new records manually, using the
C#
dbCommand.Parameters.AddWithValue()
function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900