Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 ASP.NET formview problems

Author  Topic 

bbhoss
Starting Member

1 Post

Posted - 2005-12-18 : 18:33:10
I've got a page im working on, that reads data from a local sql 2005 server. All of the connections test alright, but when i try to use FormView to insert a new row, i get this:
QUOTE

Incorrect syntax near 'nvarchar'.
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: Incorrect syntax near 'nvarchar'.

Stack Trace
QUOTE

[SqlException (0x80131904): Incorrect syntax near 'nvarchar'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +186
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(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.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +407
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +149
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +493
System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +553
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +173
System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) +626
System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +745
System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +163
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +107
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +178
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838


The code for the particualar page is below:
CODE

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
FormView1.DefaultMode = FormViewMode.Edit
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center">
<strong><span style="font-size: 24pt">
Add Casting Reels Info</span></strong><br />
<br />

<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="ID"
DataSourceID="SqlDataSource1" DefaultMode="Insert">
<EditItemTemplate>
Model:
<asp:TextBox ID="ModelTextBox" runat="server" Text='<%# Bind("Model") %>'>
</asp:TextBox><br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>'>
</asp:TextBox><br />
Price:
<asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>'>
</asp:TextBox><br />
Ball Bearings:
<asp:TextBox ID="Ball_BearingsTextBox" runat="server" Text='<%# Bind("[Ball Bearings]") %>'>
</asp:TextBox><br />
Gear Ratio:
<asp:TextBox ID="Gear_RatioTextBox" runat="server" Text='<%# Bind("[Gear Ratio]") %>'>
</asp:TextBox><br />
Line Capacity/lb:
<asp:TextBox ID="Line_Capacity_lbTextBox" runat="server" Text='<%# Bind("[Line Capacity/lb]") %>'>
</asp:TextBox><br />
Weight:
<asp:TextBox ID="WeightTextBox" runat="server" Text='<%# Bind("Weight") %>'>
</asp:TextBox><br />
ID:
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
Model:
<asp:TextBox ID="ModelTextBox" runat="server" Text='<%# Bind("Model") %>'>
</asp:TextBox><br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>'>
</asp:TextBox><br />
Price:
<asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>'>
</asp:TextBox><br />
Ball Bearings:
<asp:TextBox ID="Ball_BearingsTextBox" runat="server" Text='<%# Bind("[Ball Bearings]") %>'>
</asp:TextBox><br />
Gear Ratio:
<asp:TextBox ID="Gear_RatioTextBox" runat="server" Text='<%# Bind("[Gear Ratio]") %>'>
</asp:TextBox><br />
Line Capacity/lb:
<asp:TextBox ID="Line_Capacity_lbTextBox" runat="server" Text='<%# Bind("[Line Capacity/lb]") %>'>
</asp:TextBox><br />
Weight:
<asp:TextBox ID="WeightTextBox" runat="server" Text='<%# Bind("Weight") %>'>
</asp:TextBox><br />
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
Model:
<asp:Label ID="ModelLabel" runat="server" Text='<%# Bind("Model") %>'></asp:Label><br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>'></asp:Label><br />
Price:
<asp:Label ID="PriceLabel" runat="server" Text='<%# Bind("Price") %>'></asp:Label><br />
Ball Bearings:
<asp:Label ID="Ball_BearingsLabel" runat="server" Text='<%# Bind("[Ball Bearings]") %>'>
</asp:Label><br />
Gear Ratio:
<asp:Label ID="Gear_RatioLabel" runat="server" Text='<%# Bind("[Gear Ratio]") %>'>
</asp:Label><br />
Line Capacity/lb:
<asp:Label ID="Line_Capacity_lbLabel" runat="server" Text='<%# Bind("[Line Capacity/lb]") %>'>
</asp:Label><br />
Weight:
<asp:Label ID="WeightLabel" runat="server" Text='<%# Bind("Weight") %>'></asp:Label><br />
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:reelsConnectionString2 %>" DeleteCommand="DELETE FROM [casting] WHERE [ID] = @original_ID AND [Model] = @original_Model AND [Name] = @original_Name AND [Price] = @original_Price AND [Ball Bearings] = @original_Ball_Bearings AND [Gear Ratio] = @original_Gear_Ratio AND [Line Capacity/lb] = @original_column1 AND [Weight] = @original_Weight"
InsertCommand="INSERT INTO [casting] ([Model], [Name], [Price], [Ball Bearings], [Gear Ratio], [Line Capacity/lb], [Weight], [ID]) VALUES (@Model, @Name, @Price, @Ball_Bearings, @Gear_Ratio, @column1, @Weight, @ID)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [casting]"
UpdateCommand="UPDATE [casting] SET [Model] = @Model, [Name] = @Name, [Price] = @Price, [Ball Bearings] = @Ball_Bearings, [Gear Ratio] = @Gear_Ratio, [Line Capacity/lb] = @column1, [Weight] = @Weight WHERE [ID] = @original_ID AND [Model] = @original_Model AND [Name] = @original_Name AND [Price] = @original_Price AND [Ball Bearings] = @original_Ball_Bearings AND [Gear Ratio] = @original_Gear_Ratio AND [Line Capacity/lb] = @original_column1 AND [Weight] = @original_Weight">
<DeleteParameters>
<asp:Parameter Name="original_ID" Type="Int32" />
<asp:Parameter Name="original_Model" Type="String" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_Price" Type="String" />
<asp:Parameter Name="original_Ball_Bearings" Type="String" />
<asp:Parameter Name="original_Gear_Ratio" Type="String" />
<asp:Parameter Name="original_column1" Type="String" />
<asp:Parameter Name="original_Weight" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Model" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="Ball_Bearings" Type="String" />
<asp:Parameter Name="Gear_Ratio" Type="String" />
<asp:Parameter Name="column1" Type="String" />
<asp:Parameter Name="Weight" Type="String" />
<asp:Parameter Name="original_ID" Type="Int32" />
<asp:Parameter Name="original_Model" Type="String" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_Price" Type="String" />
<asp:Parameter Name="original_Ball_Bearings" Type="String" />
<asp:Parameter Name="original_Gear_Ratio" Type="String" />
<asp:Parameter Name="original_column1" Type="String" />
<asp:Parameter Name="original_Weight" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Model" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Price" Type="String" />
<asp:Parameter Name="Ball_Bearings" Type="String" />
<asp:Parameter Name="Gear_Ratio" Type="String" />
<asp:Parameter Name="column1" Type="String" />
<asp:Parameter Name="Weight" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
   

- Advertisement -