How do I insert data using a DetailsView into an access database without everything breaking?

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-04-19T17:03:51Z Indexed on 2010/05/16 20:30 UTC
Read the original article Hit count: 453

Hey

I'm getting the error: Data type mismatch in criteria expression. when I try to submit a DetailsView insert.

Code for Default.aspx: (from inside an asp:Content tag)

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
        AutoGenerateRows="False" DataKeyNames="user_id" 
        DataSourceID="AccessDataSource1" CellPadding="4" ForeColor="#333333" 
        GridLines="None">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <Fields>
        <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
        <asp:BoundField DataField="password" HeaderText="password" 
            SortExpression="password" />
        <asp:BoundField DataField="users_name" HeaderText="users_name" 
            SortExpression="users_name" />
        <asp:BoundField DataField="image_path" HeaderText="image_path" 
            SortExpression="image_path" />
        <asp:BoundField DataField="mobile" HeaderText="mobile" 
            SortExpression="mobile" />
        <asp:BoundField DataField="twitter" HeaderText="twitter" 
            SortExpression="twitter" />
        <asp:TemplateField HeaderText="privacy_level_id" 
            SortExpression="privacy_level_id">
            <InsertItemTemplate>
                <asp:DropDownList ID="DropDownList2" runat="server" 
                    DataSourceID="AccessDataSource2" DataTextField="privacy_level_name" 
                    DataValueField="privacy_level_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [PrivacyLevels]"></asp:AccessDataSource>

</InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("date_of_birth") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="course_id" 
            SortExpression="course_id">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList3" runat="server" 
                    DataSourceID="AccessDataSource3" DataTextField="course_name" 
                    DataValueField="course_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource3" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Courses]">
                </asp:AccessDataSource>

</EditItemTemplate>
            <InsertItemTemplate>
                <asp:DropDownList ID="DropDownList22" runat="server" 
                    DataSourceID="AccessDataSource22" DataTextField="privacy_level_name" 
                    DataValueField="privacy_level_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource22" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [PrivacyLevels]"></asp:AccessDataSource>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:DropDownList ID="DropDownList3" runat="server" 
                    DataSourceID="AccessDataSource3" DataTextField="course_name" 
                    DataValueField="course_id" Enabled="False">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource3" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Courses]"></asp:AccessDataSource>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="nationality_id" SortExpression="nationality_id">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" 
                    DataSourceID="AccessDataSource20" DataTextField="nationality_name" 
                    DataValueField="nationality_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource20" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Nationalities]">
                </asp:AccessDataSource>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" 
                    DataSourceID="AccessDataSource20" DataTextField="nationality_name" 
                    DataValueField="nationality_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource20" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Nationalities]">
                </asp:AccessDataSource>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" 
                    DataSourceID="AccessDataSource20" DataTextField="nationality_name" 
                    DataValueField="nationality_id" Enabled="False">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource20" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Nationalities]">
                </asp:AccessDataSource>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="residence_id" SortExpression="residence_id">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList4" runat="server" 
                    DataSourceID="AccessDataSource4" DataTextField="residence_name" 
                    DataValueField="residence_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource4" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Residences]"></asp:AccessDataSource>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:DropDownList ID="DropDownList4" runat="server" 
                    DataSourceID="AccessDataSource4" DataTextField="residence_name" 
                    DataValueField="residence_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource4" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Residences]"></asp:AccessDataSource>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:DropDownList ID="DropDownList4" runat="server" 
                    DataSourceID="AccessDataSource4" DataTextField="residence_name" 
                    DataValueField="residence_id" Enabled="False">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource4" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Residences]"></asp:AccessDataSource>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="course_year" HeaderText="course_year" 
            SortExpression="course_year" />
        <asp:TemplateField HeaderText="gender_id" SortExpression="gender_id">
            <EditItemTemplate>
                <asp:DropDownList ID="DropDownList5" runat="server" 
                    DataSourceID="AccessDataSource5" DataTextField="gender_name" 
                    DataValueField="gender_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource5" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Genders]"></asp:AccessDataSource>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:DropDownList ID="DropDownList5" runat="server" 
                    DataSourceID="AccessDataSource5" DataTextField="gender_name" 
                    DataValueField="gender_id">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource5" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Genders]"></asp:AccessDataSource>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:DropDownList ID="DropDownList5" runat="server" 
                    DataSourceID="AccessDataSource5" DataTextField="gender_name" 
                    DataValueField="gender_id" Enabled="False">
                </asp:DropDownList>
                <asp:AccessDataSource ID="AccessDataSource5" runat="server" 
                    DataFile="~/App_Data/VisageFinal.mdb" 
                    SelectCommand="SELECT * FROM [Genders]"></asp:AccessDataSource>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowInsertButton="True" InsertText="Create my user!" />
    </Fields>
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#999999" />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:DetailsView>


    <asp:Button ID="Button1" runat="server" Text="Button" />


    <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/VisageFinal.mdb" 
        DeleteCommand="DELETE FROM [Users] WHERE [user_id] = ?" 
        InsertCommand="INSERT INTO [Users] ([email], [password], [users_name], [image_path], [mobile], [twitter], [privacy_level_id], [nationality_id], [course_id], [residence_id], [course_year], [gender_id]) VALUES ('?', '?', '?', '?', '?', '?', ?, ?, ?, ?, ?, ?)" 
        SelectCommand="SELECT * FROM [Users]" 

        UpdateCommand="UPDATE [Users] SET [email] = ?, [password] = ?, [users_name] = ?, [date_of_birth] = ?, [image_path] = ?, [mobile] = ?, [twitter] = ?, [privacy_level_id] = ?, [nationality_id] = ?, [course_id] = ?, [residence_id] = ?, [has_set_privacy_level] = ?, [course_year] = ?, [gender_id] = ? WHERE [user_id] = ?">
        <DeleteParameters>
            <asp:Parameter Name="user_id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="email" Type="String" />
            <asp:Parameter Name="password" Type="String" />
            <asp:Parameter Name="users_name" Type="String" />

            <asp:Parameter Name="image_path" Type="String" />
            <asp:Parameter Name="mobile" Type="String" />
            <asp:Parameter Name="twitter" Type="String" />
            <asp:Parameter Name="privacy_level_id" Type="Int32" />
            <asp:Parameter Name="nationality_id" Type="Int32" />
            <asp:Parameter Name="course_id" Type="Int32" />
            <asp:Parameter Name="residence_id" Type="Int32" />
            <asp:Parameter Name="has_set_privacy_level" Type="Boolean" />
            <asp:Parameter Name="course_year" Type="Int32" />
            <asp:Parameter Name="gender_id" Type="Int32" />
            <asp:Parameter Name="user_id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>

            <asp:Parameter Name="email" Type="String" />
            <asp:Parameter Name="password" Type="String" />
            <asp:Parameter Name="users_name" Type="String" />

            <asp:Parameter Name="image_path" Type="String" />
            <asp:Parameter Name="mobile" Type="String" />
            <asp:Parameter Name="twitter" Type="String" />
            <asp:Parameter Name="privacy_level_id" Type="Int32" />
            <asp:Parameter Name="nationality_id" Type="Int32" />
            <asp:Parameter Name="course_id" Type="Int32" />
            <asp:Parameter Name="residence_id" Type="Int32" />

            <asp:Parameter Name="course_year" Type="Int32" />
            <asp:Parameter Name="gender_id" Type="Int32" />
        </InsertParameters>
    </asp:AccessDataSource>

Any ideas what I've broken?

© Stack Overflow or respective owner

Related posts about ms-access

Related posts about visual-web-developer