Visual Web Developer 2008 - ASP - Formview和Inserts

时间:2009-12-10 20:25:03

标签: asp.net ms-access-2007 visual-web-developer

我正在使用:

Visual Web Developer 2009 Access 2007

我正在尝试插入到产品表中,但我不断收到错误: “标准表达式中的数据类型不匹配。”

编辑和删除部分工作正常..

    

编辑产品

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="product_id" DataSourceID="AccessDataSource1" DefaultMode="Insert" 
        Height="50px" Width="125px">
        <Fields>
            <asp:BoundField DataField="product_id" HeaderText="product_id" 
                InsertVisible="False" ReadOnly="True" SortExpression="product_id" />
            <asp:BoundField DataField="product_name" HeaderText="product_name" 
                SortExpression="product_name" />
            <asp:BoundField DataField="product_desc" HeaderText="product_desc" 
                SortExpression="product_desc" />
            <asp:BoundField DataField="product_cost" HeaderText="product_cost" 
                SortExpression="product_cost" />
            <asp:BoundField DataField="product_amount" HeaderText="product_amount" 
                SortExpression="product_amount" />
            <asp:BoundField DataField="category_id" HeaderText="category_id" 
                SortExpression="category_id" />
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/Fandangles.mdb" 
        DeleteCommand="DELETE FROM [product] WHERE [product_id] = ?" 
        InsertCommand="INSERT INTO [product] ([product_name], [product_desc], [product_cost], [product_amount], [category_id]) VALUES (?, ?, ?, ?, ?)" 
        SelectCommand="SELECT * FROM [product]" 
        UpdateCommand="UPDATE [product] SET [product_name] = ?, [product_desc] = ?, [product_cost] = ?, [product_amount] = ?, [category_id] = ? WHERE [product_id] = ?">
        <DeleteParameters>
            <asp:Parameter Name="product_id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="product_name" Type="String" />
            <asp:Parameter Name="product_desc" Type="String" />
            <asp:Parameter Name="product_cost" Type="Decimal" />
            <asp:Parameter Name="product_amount" Type="Int32" />
            <asp:Parameter Name="category_id" Type="Int32" />
            <asp:Parameter Name="product_id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="product_id" Type="Int32" />
            <asp:Parameter Name="product_name" Type="String" />
            <asp:Parameter Name="product_desc" Type="String" />
            <asp:Parameter Name="product_cost" Type="Decimal" />
            <asp:Parameter Name="product_amount" Type="Int32" />
            <asp:Parameter Name="category_id" Type="Int32" />
        </InsertParameters>
    </asp:AccessDataSource>
</p>
</asp:Content>


DB: Access DB

product_id  -   Autonumber
product_name    -   Text
product_desc    -   Text
product_cost    -   Currency
product_amount  -   Number
category_id     -   Number - This is a lookup field 

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您真的需要将主键“product_id”传递给插入内容吗?如果不需要它的身份/ PK。

它不是插入SQL中的参数,但它是datasoruces中的参数插入参数。

试试这个

<InsertParameters>
        <asp:Parameter Name="product_id" Type="Int32" />
        <asp:Parameter Name="product_name" Type="String" />
        <asp:Parameter Name="product_desc" Type="String" />
        <asp:Parameter Name="product_cost" Type="Decimal" />
        <asp:Parameter Name="product_amount" Type="Int32" />
        <asp:Parameter Name="category_id" Type="Int32" />
</InsertParameters>