Error Updating SQL DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Trez
    New Member
    • Jun 2007
    • 1

    Error Updating SQL DB

    Hey guys,
    Am new at using ASP.Net. am having some problems updating my SQL DB. whenever i try i get this Error. Can someone help me?

    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.Sql Client.SqlExcep tion: Incorrect syntax near 'nvarchar'.

    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): Incorrect syntax near 'nvarchar'.]
    System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection ) +177
    System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection ) +68
    System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj) +199
    System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj) +2305
    System.Data.Sql Client.SqlComma nd.FinishExecut eReader(SqlData Reader ds, RunBehavior runBehavior, String resetOptionsStr ing) +147
    System.Data.Sql Client.SqlComma nd.RunExecuteRe aderTds(Command Behavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1021
    System.Data.Sql Client.SqlComma nd.RunExecuteRe ader(CommandBeh avior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +314
    System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) +413
    System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +115
    System.Web.UI.W ebControls.SqlD ataSourceView.E xecuteDbCommand (DbCommand command, DataSourceOpera tion operation) +392
    System.Web.UI.W ebControls.SqlD ataSourceView.E xecuteUpdate(ID ictionary keys, IDictionary values, IDictionary oldValues) +643
    System.Web.UI.D ataSourceView.U pdate(IDictiona ry keys, IDictionary values, IDictionary oldValues, DataSourceViewO perationCallbac k callback) +78
    System.Web.UI.W ebControls.Form View.HandleUpda te(String commandArg, Boolean causesValidatio n) +1151
    System.Web.UI.W ebControls.Form View.HandleEven t(EventArgs e, Boolean causesValidatio n, String validationGroup ) +450
    System.Web.UI.W ebControls.Form View.OnBubbleEv ent(Object source, EventArgs e) +88
    System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args) +35
    System.Web.UI.W ebControls.Form ViewRow.OnBubbl eEvent(Object source, EventArgs e) +109
    System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args) +35
    System.Web.UI.W ebControls.Link Button.OnComman d(CommandEventA rgs e) +86
    System.Web.UI.W ebControls.Link Button.RaisePos tBackEvent(Stri ng eventArgument) +156
    System.Web.UI.W ebControls.Link Button.System.W eb.UI.IPostBack EventHandler.Ra isePostBackEven t(String eventArgument) +7
    System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +11
    System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +172
    System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +4921


    Here is my code

    <%@ Page Language="VB" MasterPageFile= "~/MasterPage.mast er" AutoEventWireup ="false" CodeFile="LostA ndFound.aspx.vb " Inherits="Defau lt2" title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1" Runat="Server">
    <table>
    <tr>
    <td style="width: 312px; height: 5px">
    </td>
    <td style="width: 100px; height: 5px">
    </td>
    <td style="width: 100px; height: 5px">
    </td>
    <td style="width: 100px; height: 5px">
    </td>
    </tr>
    <tr>
    <td style="width: 312px; height: 25px">
    </td>
    <td colspan="2" style="height: 25px; text-align: center">
    <strong><span style="font-size: 16pt; color: olive; font-family: Verdana">Lost and Found</span></strong></td>
    <td style="width: 100px; height: 25px">
    </td>
    </tr>
    <tr>
    <td style="width: 312px; height: 257px">
    </td>
    <td colspan="2" style="height: 257px; vertical-align: top; text-align: left;">
    &nbsp;&nbsp;&nb sp; &nbsp;&nbsp;&nb sp;
    <asp:FormView ID="FormView1" runat="server" CellPadding="4" DataKeyNames="I tem ID"
    DataSourceID="S qlDataSource1" ForeColor="#333 333">
    <FooterStyle BackColor="#990 000" Font-Bold="True" ForeColor="Whit e" />
    <EditItemTempla te>
    <table>
    <tr>
    <td style="width: 156px">
    Item ID:
    </td>
    <td style="width: 100px">
    <asp:Label ID="Item_IDLabe l1" runat="server" Text='<%# Eval("[Item ID]") %>'></asp:Label></td>
    </tr>
    <tr>
    <td style="width: 156px">
    Date:</td>
    <td style="width: 100px">
    <asp:TextBox ID="DateTextBox " runat="server" Text='<%# Bind("Date") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 156px">
    Book Title:</td>
    <td style="width: 100px">
    <asp:TextBox ID="Book_TitleT extBox" runat="server" Text='<%# Bind("[Book Title]") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 156px">
    Book Number:
    </td>
    <td style="width: 100px">
    <asp:TextBox ID="Book_Number TextBox" runat="server" Text='<%# Bind("[Book Number]") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 156px">
    Student Name:
    </td>
    <td style="width: 100px">
    <asp:TextBox ID="Student_Nam eTextBox" runat="server" Text='<%# Bind("[Student Name]") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 156px">
    Grade:
    </td>
    <td style="width: 100px">
    <asp:TextBox ID="GradeTextBo x" runat="server" Text='<%# Bind("Grade") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 156px">
    Date Recieved:
    </td>
    <td style="width: 100px">
    <asp:TextBox ID="Date_Reciev edTextBox" runat="server" Text='<%# Bind("[Date Recieved]") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td colspan="2">
    <asp:LinkButt on ID="UpdateButto n" runat="server" CausesValidatio n="True" CommandName="Up date"
    Text="Update"></asp:LinkButton>
    <asp:LinkButt on ID="UpdateCance lButton" runat="server" CausesValidatio n="False" CommandName="Ca ncel"
    Text="Cancel"></asp:LinkButton> </td>
    </tr>
    </table>
    </EditItemTemplat e>
    <RowStyle BackColor="#FFF BD6" ForeColor="#333 333" />
    <PagerStyle BackColor="#FFC C66" ForeColor="#333 333" HorizontalAlign ="Center" />
    <InsertItemTemp late>
    <table>
    <tr>
    <td style="width: 153px">
    Date:
    </td>
    <td style="width: 100px">
    <asp:TextBox ID="DateTextBox " runat="server" Text='<%# Bind("Date") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 153px">
    Book Title:</td>
    <td style="width: 100px">
    <asp:TextBox ID="Book_TitleT extBox" runat="server" Text='<%# Bind("[Book Title]") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 153px">
    Book Number:</td>
    <td style="width: 100px">
    <asp:TextBox ID="Book_Number TextBox" runat="server" Text='<%# Bind("[Book Number]") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 153px">
    Student Name:
    </td>
    <td style="width: 100px">
    <asp:TextBox ID="Student_Nam eTextBox" runat="server" Text='<%# Bind("[Student Name]") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 153px">
    Grade:</td>
    <td style="width: 100px">
    <asp:TextBox ID="GradeTextBo x" runat="server" Text='<%# Bind("Grade") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width: 153px">
    Date Recieved:</td>
    <td style="width: 100px">
    <asp:TextBox ID="Date_Reciev edTextBox" runat="server" Text='<%# Bind("[Date Recieved]") %>'></asp:TextBox></td>
    </tr>
    <tr>
    <td colspan="2">
    <asp:LinkButt on ID="InsertButto n" runat="server" CausesValidatio n="True" CommandName="In sert"
    Text="Insert"></asp:LinkButton>
    <asp:LinkButt on ID="InsertCance lButton" runat="server" CausesValidatio n="False" CommandName="Ca ncel"
    Text="Cancel"></asp:LinkButton> </td>
    </tr>
    </table>
    </InsertItemTempl ate>
    <ItemTemplate >
    <table>
    <tr>
    <td style="width: 138px">
    Item ID:
    </td>
    <td style="width: 108px">
    <asp:Label ID="Item_IDLabe l" runat="server" Text='<%# Eval("[Item ID]") %>'></asp:Label></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Date:
    </td>
    <td style="width: 108px">
    <asp:Label ID="DateLabel" runat="server" Text='<%# Bind("Date") %>'></asp:Label></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Book Title:</td>
    <td style="width: 108px">
    <asp:Label ID="Book_TitleL abel" runat="server" Text='<%# Bind("[Book Title]") %>'
    Width="175px"></asp:Label></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Book Number:
    </td>
    <td style="width: 108px">
    <asp:Label ID="Book_Number Label" runat="server" Text='<%# Bind("[Book Number]") %>'></asp:Label></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Student Name:
    </td>
    <td style="width: 108px">
    <asp:Label ID="Student_Nam eLabel" runat="server" Text='<%# Bind("[Student Name]") %>'></asp:Label></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Grade:</td>
    <td style="width: 108px">
    <asp:Label ID="GradeLabel " runat="server" Text='<%# Bind("Grade") %>'></asp:Label></td>
    </tr>
    <tr>
    <td style="width: 138px">
    Date Recieved:</td>
    <td style="width: 108px">
    <asp:Label ID="Date_Reciev edLabel" runat="server" Text='<%# Bind("[Date Recieved]") %>'></asp:Label></td>
    </tr>
    <tr>
    <td colspan="2">
    <asp:LinkButt on ID="EditButton " runat="server" CausesValidatio n="False" CommandName="Ed it"
    Text="Edit"></asp:LinkButton>
    <asp:LinkButt on ID="DeleteButto n" runat="server" CausesValidatio n="False" CommandName="De lete"
    Text="Delete"></asp:LinkButton>
    <asp:LinkButt on ID="NewButton" runat="server" CausesValidatio n="False" CommandName="Ne w"
    Text="New"></asp:LinkButton> </td>
    </tr>
    </table>
    </ItemTemplate>
    <HeaderStyle BackColor="#990 000" Font-Bold="True" ForeColor="Whit e" />
    <HeaderTemplate >
    <span style="font-size: 16pt; color: #ffffff; font-family: Verdana">Lost and Found</span>
    </HeaderTemplate>
    </asp:FormView>
    &nbsp;
    </td>
    <td style="width: 100px; height: 257px">
    </td>
    </tr>
    <tr>
    <td style="width: 312px; height: 44px; text-align: right">
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    <asp:HyperLin k ID="HyperLink1 " runat="server" Font-Bold="True" Font-Names="Verdana"
    Font-Size="Smaller" ImageUrl="~/Images/back.gif" NavigateUrl="~/Admin/Admin.aspx"
    Style="text-align: right" Target="_parent "><< Back</asp:HyperLink></td>
    <td style="width: 100px; height: 44px">
    </td>
    <td style="width: 100px; height: 44px">
    </td>
    <td style="width: 100px; height: 44px">
    </td>
    </tr>
    </table>
    <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server" ConflictDetecti on="CompareAllV alues"
    ConnectionStrin g="<%$ ConnectionStrin gs:CortexConnec tionString41 %>" DeleteCommand=" DELETE FROM [LOST_FOUND] WHERE [Item ID] = @original_Item_ ID AND [Date] = @original_Date AND [Book Title] = @original_Book_ Title AND [Book Number] = @original_Book_ Number AND [Student Name] = @original_Stude nt_Name AND [Grade] = @original_Grade AND [Date Recieved] = @original_Date_ Recieved"
    InsertCommand=" INSERT INTO [LOST_FOUND] ([Date], [Book Title], [Book Number], [Student Name], [Grade], [Date Recieved]) VALUES (@Date, @Book_Title, @Book_Number, @Student_Name, @Grade, @Date_Recieved) "
    OldValuesParame terFormatString ="{0}" SelectCommand=" SELECT * FROM [LOST_FOUND] ORDER BY [Date]"
    UpdateCommand=" UPDATE [LOST_FOUND] SET [Date] = @Date, [Book Title] = @Book_Title, [Book Number] = @Book_Number, [Student Name] = @Student_Name, [Grade] = @Grade, [Date Recieved] = @Date_Recieved WHERE [Item ID] = @original_Item_ ID AND [Date] = @original_Date AND [Book Title] = @original_Book_ Title AND [Book Number] = @original_Book_ Number AND [Student Name] = @original_Stude nt_Name AND [Grade] = @original_Grade AND [Date Recieved] = @original_Date_ Recieved">
    <DeleteParamete rs>
    <asp:Paramete r Name="original_ Item_ID" Type="Int32" />
    <asp:Paramete r Name="original_ Date" Type="String" />
    <asp:Paramete r Name="original_ Book_Title" Type="String" />
    <asp:Paramete r Name="original_ Book_Number" Type="String" />
    <asp:Paramete r Name="original_ Student_Name" Type="String" />
    <asp:Paramete r Name="original_ Grade" Type="String" />
    <asp:Paramete r Name="original_ Date_Recieved" Type="String" />
    </DeleteParameter s>
    <UpdateParamete rs>
    <asp:Paramete r Name="Date" Type="String" />
    <asp:Paramete r Name="Book_Titl e" Type="String" />
    <asp:Paramete r Name="Book_Numb er" Type="String" />
    <asp:Paramete r Name="Student_N ame" Type="String" />
    <asp:Paramete r Name="Grade" Type="String" />
    <asp:Paramete r Name="Date_Reci eved" Type="String" />
    <asp:Paramete r Name="original_ Item_ID" Type="Int32" />
    <asp:Paramete r Name="original_ Date" Type="String" />
    <asp:Paramete r Name="original_ Book_Title" Type="String" />
    <asp:Paramete r Name="original_ Book_Number" Type="String" />
    <asp:Paramete r Name="original_ Student_Name" Type="String" />
    <asp:Paramete r Name="original_ Grade" Type="String" />
    <asp:Paramete r Name="original_ Date_Recieved" Type="String" />
    </UpdateParameter s>
    <InsertParamete rs>
    <asp:Paramete r Name="Date" Type="String" />
    <asp:Paramete r Name="Book_Titl e" Type="String" />
    <asp:Paramete r Name="Book_Numb er" Type="String" />
    <asp:Paramete r Name="Student_N ame" Type="String" />
    <asp:Paramete r Name="Grade" Type="String" />
    <asp:Paramete r Name="Date_Reci eved" Type="String" />
    </InsertParameter s>
    </asp:SqlDataSour ce>
    </asp:Content>

  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Welcome to TSDN. I'm not sure why you pasted so much code. You'll need to debug the sql and work out which variable is the problem, I can't tell which it is by your code.

    Comment

    • Wing
      New Member
      • Jun 2007
      • 28

      #3
      Your error is going to be on LostAndFound.as px.vb dealing with SQL statement near 'nvarchar' Since you are using ASP use Response.Write to display your SQL statement before committing it the database.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        That certainly is a lot of code!
        What we really need to see is your VB code (not the HTML) that you have written to connect to your database.

        Please only post that code snippet and please use [code=vbnet] ...your code [ /code]

        Thanks

        -Frinny

        Comment

        Working...