[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

Error from gridview on Update Statement in Asp.net

Asked by BofADev in Programming for ASP.NET

Tags: gridview

What seems to be an easy task of updating fields in a sql table from a gridview has become a nightmare.   I am using asp.net.  I have a gridview on a page that allows the user to Edit records.  On update, I have two web methods where one appends a change record to a table and the other updates the original record in the table.   Both are working fine and I can see the new record in table 1 and the changed fields in Table 2 based on the new values of my gridview.   All works fine until my code exits gridview1_rowupdating  and I am returned an error.  I have searched online for this error and to no avail have found anything useful.   Can someone review my code and possibly point out what I am doing wrong?  I originally was thinking it was sql that was returning the error, but both my statements are working.  Code is posted below.  The Error I am receiving is:  Incorrect syntax near 'True'  
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'True'.
stack Trace:
[SqlException (0x80131904): Incorrect syntax near 'True'.]
   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.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +912
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +179
   System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1139
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +835
   System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +162
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +118
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +106
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +175
   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) +242
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

Source:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="LookUpSale1.aspx.vb" Inherits="LookUpSale1" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    </form>
</body>
</html>--%>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <asp:Label ID="Label1" runat="server" Text="Look Up Sale Info and Make Changes"></asp:Label><br />
    <br />
    <asp:Label ID="Label2" runat="server" Text="Search by NBID"></asp:Label>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
    <asp:Label ID="Label3" runat="server" Text="Search by Loan Number"></asp:Label><br />
    <asp:TextBox ID="txtNBID" runat="server"></asp:TextBox>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp;
    <asp:TextBox ID="txtLoanNumber" runat="server"></asp:TextBox><br />
    <br />
    <asp:Label ID="Label4" runat="server" Text="Date Range"></asp:Label><br />
    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem Value="30 Days"></asp:ListItem>
        <asp:ListItem Value="60 Days"></asp:ListItem>
        <asp:ListItem Value="90 Days"></asp:ListItem>
        <asp:ListItem Value="ALL"></asp:ListItem>
    </asp:DropDownList>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    <asp:Button ID="btnLookUp" runat="server" Text="Look Up Sale Info" /><br />
    <br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True"
        CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" DataKeyNames="UID">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:BoundField DataField="datetime" HeaderText="datetime" SortExpression="datetime" />
            <asp:BoundField DataField="LoanNumber" HeaderText="LoanNumber" SortExpression="LoanNumber" />
            <asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
            <asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" />
            <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
            <asp:TemplateField HeaderText="VerifiedStatus" SortExpression="VerifiedStatus">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="ReasonCodes" DataTextField="Reason"
                        DataValueField="Reason" SelectedValue='<%# Bind("VerifiedStatus") %>'>
                    </asp:DropDownList><asp:SqlDataSource ID="ReasonCodes" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        SelectCommand="SELECT [Reason] FROM [Heloc_SalesChangeReason]"></asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("VerifiedStatus") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="DateVerified" HeaderText="DateVerified" SortExpression="DateVerified" />
            <asp:BoundField DataField="UID" HeaderText="UID" SortExpression="UID" />
            <asp:BoundField DataField="ReferringNBID" HeaderText="ReferringNBID" SortExpression="ReferringNBID" />
        </Columns>
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <EditRowStyle BackColor="#999999" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="sp_HelocSaleLookUpNBID" SelectCommandType="StoredProcedure" UpdateCommand="UPDATE Sales SET UserID = @UserID, Product = @Product , Amount = @Amount, VerifiedStatus = @VerifiedStatus, DateVerified = date(), VerifiedUser = 'webauto', ReferringNBID = @ReferrID">
        <UpdateParameters>
            <asp:ControlParameter ControlID="GridView1" Name="UserID" PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="GridView1" Name="Product" PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="GridView1" Name="Amount" PropertyName="SelectedValue" />
            <asp:Parameter Name="VerifiedStatus" />
            <asp:ControlParameter ControlID="GridView1" Name="ReferrID" PropertyName="SelectedValue" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="txtNBID" Name="NBID" PropertyName="Text" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="sp_HelocSalesLookUpLoanNumber" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:ControlParameter ControlID="txtLoanNumber" Name="LoanNumber" PropertyName="Text"
                Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True"
        CellPadding="4" DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None" DataKeyNames="UID">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:BoundField DataField="datetime" HeaderText="datetime" SortExpression="datetime" />
            <asp:BoundField DataField="LoanNumber" HeaderText="LoanNumber" SortExpression="LoanNumber" />
            <asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
            <asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" />
            <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
            <asp:TemplateField HeaderText="VerifiedStatus" SortExpression="VerifiedStatus">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="ReasonCodes1" DataTextField="Reason"
                        DataValueField="Reason" SelectedValue='<%# Bind("VerifiedStatus") %>'>
                    </asp:DropDownList><asp:SqlDataSource ID="ReasonCodes1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        SelectCommand="SELECT [Reason] FROM [Heloc_SalesChangeReason]"></asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("VerifiedStatus") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="DateVerified" HeaderText="DateVerified" SortExpression="DateVerified" />
            <asp:BoundField DataField="UID" HeaderText="UID" SortExpression="UID" />
            <asp:BoundField DataField="ReferringNBID" HeaderText="ReferringNBID" SortExpression="ReferringNBID" />
        </Columns>
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <EditRowStyle BackColor="#999999" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <br />
    <br />
    <br />
    <br />
</asp:Content>
Code Behind:
 Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim verification As New Verification
        Dim strToday As Date
        strToday = Today()


        If GridView1.Rows.Count <> 0 Then
            For i As Integer = 0 To GridView1.Rows.Count - 1
                Dim myDropDown As DropDownList
                myDropDown = GridView1.Rows(i).Cells(0).FindControl("DropDownList2")
                Dim myUpdatedStatus = myDropDown.SelectedValue
                Dim strReferringID As String
                Dim strNewProduct As String
                Dim strOldProduct As String
                strNewProduct = e.NewValues.Item("Product")
                strOldProduct = e.OldValues.Item("Product")
                If e.NewValues.Item("ReferringNBID") = "" Then
                    strReferringID = " "
                Else
                    strReferringID = e.NewValues.Item("ReferringNBID")
                End If
                SqlDataSource1.UpdateCommand = Global.Verification.AddChangeSaleRecord(strToday, e.NewValues.Item("UID"), e.NewValues.Item("LoanNumber"), e.NewValues.Item("UserID"), e.NewValues.Item("Product"), e.NewValues.Item("Amount"), myUpdatedStatus)
                SqlDataSource1.UpdateCommand = Global.Verification.UpdateSalesTableWithChanges(e.NewValues.Item("LoanNumber"), e.NewValues.Item("UserID"), strNewProduct, e.NewValues.Item("Amount"), myUpdatedStatus, e.NewValues.Item("datetime"), strReferringID, strOldProduct)
                Exit Sub
            Next
            Response.Redirect("http://localhost:3503/HelocManualVerification/lookupsale1.aspx")
        End If

    End Sub

WebMethods:
 <WebMethod()> _
    Public Shared Function AddChangeSaleRecord(ByVal ModifiedDate As String, ByVal salesUID As String, ByVal Loannumber As String, ByVal UserID As String, ByVal Product As String, ByVal Amount As Decimal, ByVal Reason As String) As Boolean
        Try
            Dim strSQL As String
            Dim mySQL As New BankofAmerica.CSRDFramework.Data.SQL()
            mySQL.ConnectionString = ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString
            strSQL = "EXEC dbo.sp_AddChangedSale '" & ModifiedDate & "', '" & salesUID & "', '" & Loannumber & "', '" & UserID & "', '" & Product & "', '" & Amount & "', '" & Reason & "'"
            mySQL.CommandString = strSQL
            mySQL.ExecuteCommandString(False)
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function

<WebMethod()> _
      Public Shared Function UpdateSalesTableWithChanges(ByVal LoanNumber As String, ByVal UserID As String, ByVal NewProduct As String, ByVal Amount As Decimal, ByVal VerifiedStatus As String, ByVal datetime As String, ByVal ReferringID As String, ByVal OldProduct As String) As Boolean
        Try
            Dim strSQL As String
            Dim strToday1 As Date
            strToday1 = Today
            Dim mySQL As New BankofAmerica.CSRDFramework.Data.SQL
            mySQL.ConnectionString = ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString
            strSQL = "Update Sales set LoanNumber = '" & LoanNumber & "', UserID = '" & UserID & "', Product = '" & NewProduct & "', Amount = '" & Amount & "', VerifiedStatus = '" & VerifiedStatus & "', referringnbid = '" & ReferringID & "' where (LoanNumber = '" & LoanNumber & "') and (product = '" & OldProduct & "') and (datetime = '" & datetime & "')"
            mySQL.CommandString = strSQL
            mySQL.ExecuteCommandString(False)
        Catch ex As Exception
            Return False
        End Try
        Return True

    End Function

[+][-]06/19/07 11:42 AM, ID: 19318553Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/19/07 12:01 PM, ID: 19318721Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/19/07 12:31 PM, ID: 19319026Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/19/07 12:47 PM, ID: 19319182Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/19/07 01:55 PM, ID: 19319836Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Programming for ASP.NET
Tags: gridview
Sign Up Now!
Solution Provided By: samtran0331
Participating Experts: 1
Solution Grade: A
 
[+][-]06/20/07 06:25 AM, ID: 19324331Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/20/07 07:26 AM, ID: 19324862Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/20/07 09:27 AM, ID: 19326015Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/20/07 11:59 AM, ID: 19327289Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/20/07 12:15 PM, ID: 19327420Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/22/07 12:55 PM, ID: 19344377Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89