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.SqlE
xception: Incorrect syntax near 'True'.
stack Trace:
[SqlException (0x80131904): Incorrect syntax near 'True'.]
System.Data.SqlClient.SqlC
onnection.
OnError(Sq
lException
exception, Boolean breakConnection) +95
System.Data.SqlClient.SqlI
nternalCon
nection.On
Error(SqlE
xception exception, Boolean breakConnection) +82
System.Data.SqlClient.TdsP
arser.Thro
wException
AndWarning
(TdsParser
StateObjec
t stateObj) +346
System.Data.SqlClient.TdsP
arser.Run(
RunBehavio
r runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244
System.Data.SqlClient.SqlC
ommand.Fin
ishExecute
Reader(Sql
DataReader
ds, RunBehavior runBehavior, String resetOptionsString) +186
System.Data.SqlClient.SqlC
ommand.Run
ExecuteRea
derTds(Com
mandBehavi
or cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121
System.Data.SqlClient.SqlC
ommand.Run
ExecuteRea
der(Comman
dBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334
System.Data.SqlClient.SqlC
ommand.Int
ernalExecu
teNonQuery
(DbAsyncRe
sult result, String methodName, Boolean sendToPipe) +407
System.Data.SqlClient.SqlC
ommand.Exe
cuteNonQue
ry() +149
System.Web.UI.WebControls.
SqlDataSou
rceView.Ex
ecuteDbCom
mand(DbCom
mand command, DataSourceOperation operation) +493
System.Web.UI.WebControls.
SqlDataSou
rceView.Ex
ecuteUpdat
e(IDiction
ary keys, IDictionary values, IDictionary oldValues) +912
System.Web.UI.DataSourceVi
ew.Update(
IDictionar
y keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCal
lback callback) +179
System.Web.UI.WebControls.
GridView.H
andleUpdat
e(GridView
Row row, Int32 rowIndex, Boolean causesValidation) +1139
System.Web.UI.WebControls.
GridView.H
andleEvent
(EventArgs
e, Boolean causesValidation, String validationGroup) +835
System.Web.UI.WebControls.
GridView.O
nBubbleEve
nt(Object source, EventArgs e) +162
System.Web.UI.Control.Rais
eBubbleEve
nt(Object source, EventArgs args) +56
System.Web.UI.WebControls.
GridViewRo
w.OnBubble
Event(Obje
ct source, EventArgs e) +118
System.Web.UI.Control.Rais
eBubbleEve
nt(Object source, EventArgs args) +56
System.Web.UI.WebControls.
LinkButton
.OnCommand
(CommandEv
entArgs e) +106
System.Web.UI.WebControls.
LinkButton
.RaisePost
BackEvent(
String eventArgument) +175
System.Web.UI.WebControls.
LinkButton
.System.We
b.UI.IPost
BackEventH
andler.Rai
sePostBack
Event(Stri
ng eventArgument) +31
System.Web.UI.Page.RaisePo
stBackEven
t(IPostBac
kEventHand
ler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePo
stBackEven
t(NameValu
eCollectio
n postData) +242
System.Web.UI.Page.Process
RequestMai
n(Boolean includeStagesBeforeAsyncPo
int, Boolean includeStagesAfterAsyncPoi
nt) +3840
Source:
<%@ Page Language="VB" MasterPageFile="~/MasterPa
ge.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="Cont
entPlaceHo
lder1">
<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>
<asp:Label ID="Label3" runat="server" Text="Search by Loan Number"></asp:Label><br />
<asp:TextBox ID="txtNBID" runat="server"></asp:TextB
ox>
<asp:TextBox ID="txtLoanNumber" runat="server"></asp:TextB
ox><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>
<asp:Button ID="btnLookUp" runat="server" Text="Look Up Sale Info" /><br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
" AutoGenerateEditButton="Tr
ue"
CellPadding="4" DataSourceID="SqlDataSourc
e1" 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="VerifiedSt
atus">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="ReasonCodes"
DataTextField="Reason"
DataValueField="Reason" SelectedValue='<%# Bind("VerifiedStatus") %>'>
</asp:DropDownList><asp:Sq
lDataSourc
e ID="ReasonCodes" runat="server" ConnectionString="<%$ ConnectionStrings:Connecti
onString %>"
SelectCommand="SELECT [Reason] FROM [Heloc_SalesChangeReason]"
></asp:Sql
DataSource
>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("VerifiedStatus") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DateVerified" HeaderText="DateVerified" SortExpression="DateVerifi
ed" />
<asp:BoundField DataField="UID" HeaderText="UID" SortExpression="UID" />
<asp:BoundField DataField="ReferringNBID" HeaderText="ReferringNBID"
SortExpression="ReferringN
BID" />
</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:Connecti
onString %>"
SelectCommand="sp_HelocSal
eLookUpNBI
D" SelectCommandType="StoredP
rocedure" 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="SelectedValu
e" />
<asp:ControlParameter ControlID="GridView1" Name="Product" PropertyName="SelectedValu
e" />
<asp:ControlParameter ControlID="GridView1" Name="Amount" PropertyName="SelectedValu
e" />
<asp:Parameter Name="VerifiedStatus" />
<asp:ControlParameter ControlID="GridView1" Name="ReferrID" PropertyName="SelectedValu
e" />
</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:Connecti
onString %>"
SelectCommand="sp_HelocSal
esLookUpLo
anNumber" SelectCommandType="StoredP
rocedure">
<SelectParameters>
<asp:ControlParameter ControlID="txtLoanNumber" Name="LoanNumber" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False
" AutoGenerateEditButton="Tr
ue"
CellPadding="4" DataSourceID="SqlDataSourc
e2" 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="VerifiedSt
atus">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="ReasonCodes1
" DataTextField="Reason"
DataValueField="Reason" SelectedValue='<%# Bind("VerifiedStatus") %>'>
</asp:DropDownList><asp:Sq
lDataSourc
e ID="ReasonCodes1" runat="server" ConnectionString="<%$ ConnectionStrings:Connecti
onString %>"
SelectCommand="SELECT [Reason] FROM [Heloc_SalesChangeReason]"
></asp:Sql
DataSource
>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("VerifiedStatus") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DateVerified" HeaderText="DateVerified" SortExpression="DateVerifi
ed" />
<asp:BoundField DataField="UID" HeaderText="UID" SortExpression="UID" />
<asp:BoundField DataField="ReferringNBID" HeaderText="ReferringNBID"
SortExpression="ReferringN
BID" />
</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(ByVa
l sender As Object, ByVal e As System.Web.UI.WebControls.
GridViewUp
dateEventA
rgs) 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)
.FindContr
ol("DropDo
wnList2")
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("Referrin
gNBID") = "" Then
strReferringID = " "
Else
strReferringID = e.NewValues.Item("Referrin
gNBID")
End If
SqlDataSource1.UpdateComma
nd = Global.Verification.AddCha
ngeSaleRec
ord(strTod
ay, e.NewValues.Item("UID"), e.NewValues.Item("LoanNumb
er"), e.NewValues.Item("UserID")
, e.NewValues.Item("Product"
), e.NewValues.Item("Amount")
, myUpdatedStatus)
SqlDataSource1.UpdateComma
nd = Global.Verification.Update
SalesTable
WithChange
s(e.NewVal
ues.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.CSRDFramewor
k.Data.SQL
()
mySQL.ConnectionString = ConfigurationManager.Conne
ctionStrin
gs("DBConn
ectionStri
ng").Conne
ctionStrin
g
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 UpdateSalesTableWithChange
s(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.CSRDFramewor
k.Data.SQL
mySQL.ConnectionString = ConfigurationManager.Conne
ctionStrin
gs("DBConn
ectionStri
ng").Conne
ctionStrin
g
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