Chapter08
Hi,
I need help regarding the Editing and Deleting TIOs in chapter 08.
I followed all the points given in TIOs.
The Edit and Delete for the GridView is working properly.
Insert is working properly inthe DetailsView.
Now the things that are not working properly are as follows:
The select in the gridview: Whenever I am trying to select any row from the gridview ,alway the first row (fixtureid1)
is shown in the detailsview.
The UPDATE in DetailSView: Whenever I am trying to update it is giving following server error:
Server Error in '/Chapter08' Application.
--------------------------------------------------------------------------------
The data types text and nvarchar are incompatible in the equal to operator.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: The data types text and nvarchar are incompatible in the equal to operator.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): The data types text and nvarchar are incompatible in the equal to operator.]
System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) +95
System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) +82
System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +186
System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121
System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +407
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +149
System.Web.UI.WebControls.SqlDataSourceView.Execut eDbCommand(DbCommand command, DataSourceOperation operation) +493
System.Web.UI.WebControls.SqlDataSourceView.Execut eUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +915
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +179
System.Web.UI.WebControls.DetailsView.HandleUpdate (String commandArg, Boolean causesValidation) +1200
System.Web.UI.WebControls.DetailsView.HandleEvent( EventArgs e, Boolean causesValidation, String validationGroup) +545
System.Web.UI.WebControls.DetailsView.OnBubbleEven t(Object source, EventArgs e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.DetailsViewRow.OnBubbleE vent(Object source, EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +107
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String eventArgument) +175
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +244
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839
The Delete in the DetailsView also giving following errors:
Server Error in '/Chapter08' Application.
--------------------------------------------------------------------------------
The data types text and nvarchar are incompatible in the equal to operator.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: The data types text and nvarchar are incompatible in the equal to operator.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): The data types text and nvarchar are incompatible in the equal to operator.]
System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) +95
System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) +82
System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +186
System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121
System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +407
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +149
System.Web.UI.WebControls.SqlDataSourceView.Execut eDbCommand(DbCommand command, DataSourceOperation operation) +493
System.Web.UI.WebControls.SqlDataSourceView.Execut eDelete(IDictionary keys, IDictionary oldValues) +913
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +176
System.Web.UI.WebControls.DetailsView.HandleDelete (String commandArg) +810
System.Web.UI.WebControls.DetailsView.HandleEvent( EventArgs e, Boolean causesValidation, String validationGroup) +660
System.Web.UI.WebControls.DetailsView.RaisePostBac kEvent(String eventArgument) +213
System.Web.UI.WebControls.DetailsView.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +244
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839
Here is the source for Fixture.aspx:
<%@ Page Language="C#" MasterPageFile="~/site.master" AutoEventWireup="true" CodeFile="Fixtures.aspx.cs" Inherits="Fixtures" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="FixtureID"
DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
<Columns>
<asp:CommandField ShowSelectButton="True" ShowEditButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="FixtureID" HeaderText="FixtureID" ReadOnly="True" SortExpression="FixtureID" />
<asp:BoundField DataField="FixtureDate" HeaderText="FixtureDate" SortExpression="FixtureDate" />
<asp:BoundField DataField="Opponents" HeaderText="Opponents" SortExpression="Opponents" />
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
<asp:BoundField DataField="FixtureType" HeaderText="FixtureType" SortExpression="FixtureType" />
<asp:BoundField DataField="GoalsFor" HeaderText="GoalsFor" SortExpression="GoalsFor" />
<asp:BoundField DataField="GoalsAgainst" HeaderText="GoalsAgainst" SortExpression="GoalsAgainst" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WroxUnitedConnectionString1 %>"
DeleteCommand="DELETE FROM [Fixtures] WHERE [FixtureID] = @FixtureID" InsertCommand="INSERT INTO [Fixtures] ([FixtureDate], [Opponents], [Notes], [FixtureType], [GoalsFor], [GoalsAgainst]) VALUES (@FixtureDate, @Opponents, @Notes, @FixtureType, @GoalsFor, @GoalsAgainst)"
ProviderName="<%$ ConnectionStrings:WroxUnitedConnectionString1.Prov iderName %>"
SelectCommand="SELECT [FixtureID], [FixtureDate], [Opponents], [Notes], [FixtureType], [GoalsFor], [GoalsAgainst] FROM [Fixtures]"
UpdateCommand="UPDATE [Fixtures] SET [FixtureDate] = @FixtureDate, [Opponents] = @Opponents, [Notes] = @Notes, [FixtureType] = @FixtureType, [GoalsFor] = @GoalsFor, [GoalsAgainst] = @GoalsAgainst WHERE [FixtureID] = @FixtureID" OnDeleted="SqlDataSource1_Deleted" OnInserted="SqlDataSource1_Inserted" OnUpdated="SqlDataSource1_Updated">
<InsertParameters>
<asp:Parameter Name="FixtureDate" Type="DateTime" />
<asp:Parameter Name="Opponents" Type="String" />
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="FixtureType" Type="String" />
<asp:Parameter Name="GoalsFor" Type="Int16" />
<asp:Parameter Name="GoalsAgainst" Type="Int16" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="FixtureDate" Type="DateTime" />
<asp:Parameter Name="Opponents" Type="String" />
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="FixtureType" Type="String" />
<asp:Parameter Name="GoalsFor" Type="Int16" />
<asp:Parameter Name="GoalsAgainst" Type="Int16" />
<asp:Parameter Name="FixtureID" Type="Int32" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="FixtureID" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="FixtureID"
DataSourceID="SqlDataSource2" Height="91px" Width="450px">
<Fields>
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
<asp:BoundField DataField="FixtureID" HeaderText="FixtureID" InsertVisible="False"
ReadOnly="True" SortExpression="FixtureID" />
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="FixtureDate" HeaderText="FixtureDate" SortExpression="FixtureDate" />
<asp:BoundField DataField="FixtureType" HeaderText="FixtureType" SortExpression="FixtureType" />
<asp:BoundField DataField="GoalsFor" HeaderText="GoalsFor" SortExpression="GoalsFor" />
<asp:BoundField DataField="GoalsAgainst" HeaderText="GoalsAgainst" SortExpression="GoalsAgainst" />
<asp:BoundField DataField="Opponents" HeaderText="Opponents" SortExpression="Opponents" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:WroxUnited %>"
SelectCommand="SELECT [FixtureID], [FixtureDate], [FixtureType], [GoalsFor], [GoalsAgainst], [Notes], [Opponents] FROM [Fixtures]" ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [Fixtures] WHERE [FixtureID] = @original_FixtureID AND [FixtureDate] = @original_FixtureDate AND [FixtureType] = @original_FixtureType AND [GoalsFor] = @original_GoalsFor AND [GoalsAgainst] = @original_GoalsAgainst AND [Notes] = @original_Notes AND [Opponents] = @original_Opponents"
InsertCommand="INSERT INTO [Fixtures] ([FixtureDate], [FixtureType], [GoalsFor], [GoalsAgainst], [Notes], [Opponents]) VALUES (@FixtureDate, @FixtureType, @GoalsFor, @GoalsAgainst, @Notes, @Opponents)" OldValuesParameterFormatString="original_{0}"
UpdateCommand="UPDATE [Fixtures] SET [FixtureDate] = @FixtureDate, [FixtureType] = @FixtureType, [GoalsFor] = @GoalsFor, [GoalsAgainst] = @GoalsAgainst, [Notes] = @Notes, [Opponents] = @Opponents WHERE [FixtureID] = @original_FixtureID AND [FixtureDate] = @original_FixtureDate AND [FixtureType] = @original_FixtureType AND [GoalsFor] = @original_GoalsFor AND [GoalsAgainst] = @original_GoalsAgainst AND [Notes] = @original_Notes AND [Opponents] = @original_Opponents" OnDeleted="SqlDataSource2_Deleted" OnInserted="SqlDataSource2_Inserted" OnUpdated="SqlDataSource2_Updated">
<DeleteParameters>
<asp:Parameter Name="original_FixtureID" Type="Int32" />
<asp:Parameter Name="original_FixtureDate" Type="DateTime" />
<asp:Parameter Name="original_FixtureType" Type="String" />
<asp:Parameter Name="original_GoalsFor" Type="Int16" />
<asp:Parameter Name="original_GoalsAgainst" Type="Int16" />
<asp:Parameter Name="original_Notes" Type="String" />
<asp:Parameter Name="original_Opponents" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="FixtureDate" Type="DateTime" />
<asp:Parameter Name="FixtureType" Type="String" />
<asp:Parameter Name="GoalsFor" Type="Int16" />
<asp:Parameter Name="GoalsAgainst" Type="Int16" />
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="Opponents" Type="String" />
<asp:Parameter Name="original_FixtureID" Type="Int32" />
<asp:Parameter Name="original_FixtureDate" Type="DateTime" />
<asp:Parameter Name="original_FixtureType" Type="String" />
<asp:Parameter Name="original_GoalsFor" Type="Int16" />
<asp:Parameter Name="original_GoalsAgainst" Type="Int16" />
<asp:Parameter Name="original_Notes" Type="String" />
<asp:Parameter Name="original_Opponents" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="FixtureDate" Type="DateTime" />
<asp:Parameter Name="FixtureType" Type="String" />
<asp:Parameter Name="GoalsFor" Type="Int16" />
<asp:Parameter Name="GoalsAgainst" Type="Int16" />
<asp:Parameter Name="Notes" Type="String" />
<asp:Parameter Name="Opponents" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</asp:Content>
The code behind file is as follows:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Fixtures : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e)
{
DetailsView1.DataBind();
}
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
DetailsView1.DataBind();
}
protected void SqlDataSource1_Updated(object sender, SqlDataSourceStatusEventArgs e)
{
DetailsView1.DataBind();
}
protected void SqlDataSource2_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
GridView1.DataBind();
}
protected void SqlDataSource2_Updated(object sender, SqlDataSourceStatusEventArgs e)
{
GridView1.DataBind();
}
protected void SqlDataSource2_Deleted(object sender, SqlDataSourceStatusEventArgs e)
{
GridView1.DataBind();
}
}
So why it is happening.Pls help me.
Thanks in advance.
Regards,
jackSparrow
|