本文介绍了如何将参数值输入ObjectDataSource的InsertMethod中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在绑定到 ObjectDataSource 的Web表单上有一个 DataGrid .更新,删除和检索操作都可以正常工作.但是,我找不到任何方法来创建新记录.

我曾尝试将文本框放在屏幕上以接受新记录的值并提供创建"按钮,但是当我进入事件处理程序并手动调用 Insert()时, ObjectDataSource ,它表示参数集合为空.尽管事实上我的.aspx文件中包含以下内容:

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:

<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>



尽管阅读了有关该主题的所有内容,但我只是找不到任何使它起作用的方法.有谁知道该怎么做或通过 ObjectDataSource 获取数据库中创建的新记录的任何方式?

亲切的祝福〜Patrick



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

推荐答案

dbCommand.Parameters.AddWithValue()

函数手动插入新记录.


这篇关于如何将参数值输入ObjectDataSource的InsertMethod中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:53