troubleshooting Question

Detailsview Gridview same page SQL Compact Error

Avatar of atljarman
atljarman asked on
DatabasesWeb DevelopmentASP.NET
6 Comments2 Solutions348 ViewsLast Modified:
I can't get the SQL Server Compact table to link up in the linked GridView/DetailsView.

Everything functions correctly when I comment out the control parameter. Not sure if I have to set the Select statement DetailsView with script, and not even sure I know where to start with it. Anyone have any ideas on how to do this?

When I remove the comment on the control parameter I get the error: "No mapping exists from DbType Object to a known SqlDbType."

<%@ Page Title="" Language="C#" MasterPageFile="~/site.master" %>

<%@ MasterType VirtualPath='~/site.master' %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>

<%@ Import Namespace="System.Data.SqlServerCe" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Import Namespace="System.Collections.Specialized" %>

<script runat="server">
    protected void DetailsView1_ItemInserted(object sender, System.Web.UI.WebControls.DetailsViewInsertedEventArgs e)
    {


        if (((e.Exception != null)))
        {
            ErrorMessageLabel.Text = "An error occured while entering this record.  Please verify you have entered data in the correct format.";
            e.ExceptionHandled = true;
        }
        GridView1.DataBind();
    }

    protected void DetailsView1_ItemUpdated(object sender, System.Web.UI.WebControls.DetailsViewUpdatedEventArgs e)
    {

        GridView1.DataBind();
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
    }

    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {

        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
    }

    protected void GridView1_Sorted(object sender, System.EventArgs e)
    {
        DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
    }

    protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {

        if (((e.Exception != null)))
        {

            ErrorMessageLabel.Text = "Failed to DELETE due to foreign key contstraint on the table.  You may only delete rows which have no related records.";
            e.ExceptionHandled = true;
        }
    }

    protected void DetailsView1_DataBound(object sender, EventArgs e)
    {

        // if ((DetailsView1.CurrentMode == DetailsViewMode.Insert))
        //{

            //TextBox stateTextBox = (TextBox)DetailsView1.Rows(6).Cells(1).Controls(0);
            //stateTextBox.Text = DropDownList1.SelectedValue;
            //stateTextBox.Enabled = false;
        //}
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="MetaTagContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">


    <table>
      <tr>
        <td valign="top">
          <asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" runat="server"
            DataSourceID="SqlDataSource1" DataKeyNames="ItemId"
            AutoGenerateColumns="False" Width="500px" SelectedIndex="0" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnPageIndexChanged="GridView1_PageIndexChanged" OnRowDeleted="GridView1_RowDeleted" OnSorted="GridView1_Sorted">
            <Columns>
              <asp:CommandField ShowSelectButton="true" ShowDeleteButton="true" />
              <asp:BoundField DataField="ItemId" HeaderText="ItemId" ReadOnly="True" SortExpression="ItemId" />
              <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
              <asp:BoundField DataField="link" HeaderText="link" SortExpression="link" />
              <%--  <asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
                <asp:BoundField DataField="PubDate" HeaderText="PubDate" SortExpression="PubDate" />
                <asp:BoundField DataField="CreatedBy" HeaderText="CreatedBy" SortExpression="CreatedBy" />--%>
            </Columns>
          </asp:GridView>
          <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:XMLDataSourceReplacement %>"
            ProviderName="<%$ ConnectionStrings:XMLDataSourceReplacement.ProviderName %>"
            SelectCommand="SELECT * FROM [rsssource] order by pubDate desc"
            DeleteCommand="DELETE FROM [rsssource] WHERE [ItemID] = @ItemID" >
              <DeleteParameters>
                  <asp:Parameter Name="ItemID" />
              </DeleteParameters>
          </asp:SqlDataSource>
        </td>
        <td valign="top">
          <asp:DetailsView AutoGenerateRows="False" DataKeyNames="ItemId" DataSourceID="SqlDataSource3"
            HeaderText="RSS Item Details" ID="DetailsView1" runat="server" Width="275px" OnItemUpdated="DetailsView1_ItemUpdated" OnItemInserted="DetailsView1_ItemInserted" OnDataBound="DetailsView1_DataBound">
            <Fields>
              <%--<asp:BoundField DataField="ItemId" HeaderText="ItemId" ReadOnly="True" SortExpression="ItemId" />--%>
              <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
              <asp:BoundField DataField="link" HeaderText="link" SortExpression="link" />
              <asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
              <asp:BoundField DataField="CreatedBy" HeaderText="CreatedBy" SortExpression="CreatedBy" />
              <asp:BoundField DataField="PubDate" HeaderText="PubDate" ReadOnly="True" SortExpression="PubDate" />
              <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
            </Fields>
          </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:XMLDataSourceReplacement %>" 
            ProviderName="<%$ ConnectionStrings:XMLDataSourceReplacement.ProviderName %>"
            DeleteCommand="DELETE FROM [rsssource] WHERE [ItemId] = @ItemId" 
            InsertCommand="Insert Into rsssource (title, link, description, PubDate, CreatedBy) VALUES (@title, @link, @description, GetDate(), @CreatedBy)"
            SelectCommand="SELECT * FROM [rsssource]" 
            UpdateCommand="UPDATE [rsssource] SET [title] = @title, [link] = @link, [description] = @description, [PubDate] = @PubDate, [CreatedBy] = @CreatedBy WHERE [ItemId] = @ItemId">    
        <%--<SelectParameters>
              <asp:ControlParameter ControlID="GridView1" Name="ItemID" PropertyName="SelectedValue"
                Type="Object" />
        </SelectParameters>--%>
        <DeleteParameters>
            <asp:Parameter Name="ItemId" Type="Object" />
        </DeleteParameters>
        <InsertParameters>
            <%--<asp:Parameter Name="ItemId" Type="Object" />--%>
            <asp:Parameter Name="title" Type="String" />
            <asp:Parameter Name="link" Type="String" />
            <asp:Parameter Name="description" Type="String" />
            <asp:Parameter Name="PubDate" Type="DateTime" />
            <%--<asp:Parameter Name="CreatedBy" Type="String" />--%>
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="title" Type="String" />
            <asp:Parameter Name="link" Type="String" />
            <asp:Parameter Name="description" Type="String" />
            <asp:Parameter Name="PubDate" Type="DateTime" />
            <asp:Parameter Name="CreatedBy" Type="String" />
            <asp:Parameter Name="ItemId" Type="Object" />
        </UpdateParameters>
    </asp:SqlDataSource>
        </td>
      </tr>
    </table>
    <br />
    <asp:Label ID="ErrorMessageLabel" EnableViewState="false" runat="server" />
</asp:Content>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros