问题描述
嗨我在数据库RevinewDepartment中有一个表RevinewTable
[S.I.N.O] int主键IsIdentity = yes,增量= 1,种子= 1
[NameOfTheApplicant& Address] varchar(20)
[产品号] varchar(20)
[Sy.No] varchar(20)
村庄varchar(50)
曼达尔varchar(20)
地区varchar(20)
正则化范围varchar(20)
[ChallanNo.& Date] varchar(50)
[背书和日期]日期
像那样
我在Webform中使用SqlDatasource和GridView
我配置了SqlDatasource允许方式
1.smarttag->新连接->(本地)-> db是College->测试成功
2.在configure select语句中,我指定了My RevinewTable Table,在Advanced选项卡中,选择了Generate insert update delete和乐观并发
3.我测试了我的查询,效果很好
4.我将此数据源附加到我的gridview
5.我启用了选择,编辑和分页的所有功能,除了编辑
当我单击编辑"时,输入新的详细信息后,它更改为更新"和取消".
''&''附近的语法不正确.
说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的详细信息.
异常详细信息:System.Data.SqlClient.SqlException:&"附近的语法不正确.
源错误:
当前Web请求的执行期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息.
注意:
当我使用产品"表对Northwind数据库进行测试时,此过程对我来说很好用
请帮帮我
这是原始代码
HiI have a Table RevinewTable in The Database RevinewDepartment
[S.I.N.O] int Primarykey IsIdentity=yes,Increment=1,seed=1
[NameOfTheApplicant&Address] varchar(20)
[PlotNo.] varchar(20)
[Sy.No] varchar(20)
Village varchar(50)
Mandal varchar(20)
District varchar(20)
RegularisedExtent varchar(20)
[ChallanNo.&Date] varchar(50)
[Endorsement&Date] Date
Like That
I am using SqlDatasource and GridView in My Webform
I configured The SqlDatasource Fallowing way
1.smarttag-->new connection -->(local)-->db is College-->Test Succeded
2.in configure select statement i specified My RevinewTable Table and in Advanced Tab i selected Generate insert update delete and optimistic concurrency
3.I tested My query it works fine
4.I attached this datasource to My gridview
5.I enabled selecting,editing and paging all works fine except edit
when i click on edit it changed to Update and Cancel after entering new details when i click on Update it gives the Fallowing Error
Incorrect syntax near ''&''.
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 ''&''.
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.
Note:
This Process works fine for me when i test with Northwind database with Products table
Please help me
This is the original code
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:DemoRevinew1ConnectionString %>"
DeleteCommand="DELETE FROM [REGULARISEDGOM747] WHERE [S.I.N.O] = @original_column1 AND (([NameOfTheApplicant&Address] = @original_column2) OR ([NameOfTheApplicant&Address] IS NULL AND @original_column2 IS NULL)) AND (([PlotNo.] = @original_column3) OR ([PlotNo.] IS NULL AND @original_column3 IS NULL)) AND (([Sy.No] = @original_column4) OR ([Sy.No] IS NULL AND @original_column4 IS NULL)) AND (([Village] = @original_Village) OR ([Village] IS NULL AND @original_Village IS NULL)) AND (([Mandal] = @original_Mandal) OR ([Mandal] IS NULL AND @original_Mandal IS NULL)) AND (([District] = @original_District) OR ([District] IS NULL AND @original_District IS NULL)) AND (([RegularisedExtent] = @original_RegularisedExtent) OR ([RegularisedExtent] IS NULL AND @original_RegularisedExtent IS NULL)) AND (([ChallanNo.&Date] = @original_column5) OR ([ChallanNo.&Date] IS NULL AND @original_column5 IS NULL)) AND (([Endorsement&Date] = @original_column6) OR ([Endorsement&Date] IS NULL AND @original_column6 IS NULL))"
InsertCommand="INSERT INTO [REGULARISEDGOM747] ([NameOfTheApplicant&Address], [PlotNo.], [Sy.No], [Village], [Mandal], [District], [RegularisedExtent], [ChallanNo.&Date], [Endorsement&Date]) VALUES (@column1, @column2, @column3, @Village, @Mandal, @District, @RegularisedExtent, @column4, @column5)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [REGULARISEDGOM747]"
UpdateCommand="UPDATE [REGULARISEDGOM747] SET [NameOfTheApplicant&Address] = @column1, [PlotNo.] = @column2, [Sy.No] = @column3, [Village] = @Village, [Mandal] = @Mandal, [District] = @District, [RegularisedExtent] = @RegularisedExtent, [ChallanNo.&Date] = @column4, [Endorsement&Date] = @column5 WHERE [S.I.N.O] = @original_column1 AND (([NameOfTheApplicant&Address] = @original_column2) OR ([NameOfTheApplicant&Address] IS NULL AND @original_column2 IS NULL)) AND (([PlotNo.] = @original_column3) OR ([PlotNo.] IS NULL AND @original_column3 IS NULL)) AND (([Sy.No] = @original_column4) OR ([Sy.No] IS NULL AND @original_column4 IS NULL)) AND (([Village] = @original_Village) OR ([Village] IS NULL AND @original_Village IS NULL)) AND (([Mandal] = @original_Mandal) OR ([Mandal] IS NULL AND @original_Mandal IS NULL)) AND (([District] = @original_District) OR ([District] IS NULL AND @original_District IS NULL)) AND (([RegularisedExtent] = @original_RegularisedExtent) OR ([RegularisedExtent] IS NULL AND @original_RegularisedExtent IS NULL)) AND (([ChallanNo.&Date] = @original_column5) OR ([ChallanNo.&Date] IS NULL AND @original_column5 IS NULL)) AND (([Endorsement&Date] = @original_column6) OR ([Endorsement&Date] IS NULL AND @original_column6 IS NULL))">
<asp:Parameter Name="original_column1" Type="Int32" />
<asp:Parameter Name="original_column2" Type="String" />
<asp:Parameter Name="original_column3" Type="String" />
<asp:Parameter Name="original_column4" Type="String" />
<asp:Parameter Name="original_Village" Type="String" />
<asp:Parameter Name="original_Mandal" Type="String" />
<asp:Parameter Name="original_District" Type="String" />
<asp:Parameter Name="original_RegularisedExtent" Type="String" />
<asp:Parameter Name="original_column5" Type="String" />
<asp:Parameter DbType="Date" Name="original_column6" />
<asp:Parameter Name="column1" Type="String" />
< asp:参数名称="column2"类型="String"/>
< asp:参数名称="column3"类型="String"/>
< asp:参数名称=村庄"类型=字符串"/>
< asp:参数名称="Mandal"类型="String"/>
< asp:参数名称=分区"类型=字符串"/>
< asp:参数名称="RegularisedExtent"类型="String"/>
< asp:参数名称="column4"类型="String"/>
< asp:参数DbType ="Date" Name ="column5"/>
< asp:GridView ID ="GridView1" runat ="server" AllowPaging ="True"
AllowSorting ="True" AutoGenerateColumns ="False" CellPadding ="4"
DataKeyNames ="S.I.N.O" DataSourceID ="SqlDataSource1" ForeColor =#333333"
GridLines ="None">
< rowstyle backcolor =#F7F6F3" forecolor =#333333">
<列> < asp:CommandField ShowDeleteButton ="True" ShowEditButton ="True"
ShowSelectButton ="True"/>
< asp:BoundField DataField ="S.I.N.O" HeaderText ="S.I.N.O" InsertVisible ="False"
ReadOnly ="True" SortExpression ="S.I.N.O"/>
< asp:BoundField DataField ="NameOfTheApplicant& Address"
HeaderText ="NameOfTheApplicant&Address"
SortExpression ="NameOfTheApplicant&Address"/>
< asp:BoundField DataField ="PlotNo." HeaderText ="PlotNo."
SortExpression ="PlotNo." />
< asp:BoundField DataField ="Sy.No" HeaderText ="Sy.No" SortExpression ="Sy.No"/>
< asp:BoundField DataField ="Village" HeaderText ="Village"
SortExpression ="Village"/>
< asp:BoundField DataField ="Mandal" HeaderText ="Mandal"
SortExpression ="Mandal"/>
< asp:BoundField DataField ="District" HeaderText ="District"
SortExpression ="District"/>
< asp:BoundField DataField ="RegularisedExtent" HeaderText ="RegularisedExtent"
SortExpression ="RegularisedExtent"/>
< asp:BoundField DataField ="ChallanNo.& Date"
HeaderText ="ChallanNo.& Date" SortExpression ="ChallanNo.& Date"/>
< asp:BoundField DataField ="Endorsement& Date"
HeaderText ="Endorsement& Date" SortExpression ="Endorsement& Date"/>
< footerstyle backcolor =#5D7B9D" font-bold ="True" forecolor ="White">
< pagerstyle backcolor =#284775" forecolor ="White" horizontalalign ="Center">
< SelectedRowStyle BackColor =#E2DED6" Font-Bold ="True" ForeColor =#333333"/>
< HeaderStyle BackColor =#5D7B9D" Font-Bold ="True" ForeColor ="White"/>
< editrowstyle backcolor =#999999">
< alternatingrowstyle backcolor ="White" forecolor =#284775">
[edit]代码从注释变为问题-OriginalGriff [/edit]
<asp:Parameter Name="column2" Type="String" />
<asp:Parameter Name="column3" Type="String" />
<asp:Parameter Name="Village" Type="String" />
<asp:Parameter Name="Mandal" Type="String" />
<asp:Parameter Name="District" Type="String" />
<asp:Parameter Name="RegularisedExtent" Type="String" />
<asp:Parameter Name="column4" Type="String" />
<asp:Parameter DbType="Date" Name="column5" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="S.I.N.O" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<rowstyle backcolor="#F7F6F3" forecolor="#333333">
<columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="S.I.N.O" HeaderText="S.I.N.O" InsertVisible="False"
ReadOnly="True" SortExpression="S.I.N.O" />
<asp:BoundField DataField="NameOfTheApplicant&Address"
HeaderText="NameOfTheApplicant&Address"
SortExpression="NameOfTheApplicant&Address" />
<asp:BoundField DataField="PlotNo." HeaderText="PlotNo."
SortExpression="PlotNo." />
<asp:BoundField DataField="Sy.No" HeaderText="Sy.No" SortExpression="Sy.No" />
<asp:BoundField DataField="Village" HeaderText="Village"
SortExpression="Village" />
<asp:BoundField DataField="Mandal" HeaderText="Mandal"
SortExpression="Mandal" />
<asp:BoundField DataField="District" HeaderText="District"
SortExpression="District" />
<asp:BoundField DataField="RegularisedExtent" HeaderText="RegularisedExtent"
SortExpression="RegularisedExtent" />
<asp:BoundField DataField="ChallanNo.&Date"
HeaderText="ChallanNo.&Date" SortExpression="ChallanNo.&Date" />
<asp:BoundField DataField="Endorsement&Date"
HeaderText="Endorsement&Date" SortExpression="Endorsement&Date" />
<footerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White">
<pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Center">
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<editrowstyle backcolor="#999999">
<alternatingrowstyle backcolor="White" forecolor="#284775">
[edit]Code moved from comment to question - OriginalGriff[/edit]
推荐答案
< asp:参数名称="column2"类型="String"/>
< asp:参数名称="column3"类型="String"/>
< asp:参数名称=村庄"类型=字符串"/>
< asp:参数名称="Mandal"类型="String"/>
< asp:参数名称=分区"类型=字符串"/>
< asp:参数名称="RegularisedExtent"类型="String"/>
< asp:参数名称="column4"类型="String"/>
< asp:参数DbType ="Date" Name ="column5"/>
< asp:GridView ID ="GridView1" runat ="server" AllowPaging ="True"
AllowSorting ="True" AutoGenerateColumns ="False" CellPadding ="4"
DataKeyNames ="S.I.N.O" DataSourceID ="SqlDataSource1" ForeColor =#333333"
GridLines ="None">
< rowstyle backcolor =#F7F6F3" forecolor =#333333">
<列> < asp:CommandField ShowDeleteButton ="True" ShowEditButton ="True"
ShowSelectButton ="True"/>
< asp:BoundField DataField ="S.I.N.O" HeaderText ="S.I.N.O" InsertVisible ="False"
ReadOnly ="True" SortExpression ="S.I.N.O"/>
< asp:BoundField DataField ="NameOfTheApplicant& Address"
HeaderText ="NameOfTheApplicant&Address"
SortExpression ="NameOfTheApplicant&Address"/>
< asp:BoundField DataField ="PlotNo." HeaderText ="PlotNo."
SortExpression ="PlotNo." />
< asp:BoundField DataField ="Sy.No" HeaderText ="Sy.No" SortExpression ="Sy.No"/>
< asp:BoundField DataField ="Village" HeaderText ="Village"
SortExpression ="Village"/>
< asp:BoundField DataField ="Mandal" HeaderText ="Mandal"
SortExpression ="Mandal"/>
< asp:BoundField DataField ="District" HeaderText ="District"
SortExpression ="District"/>
< asp:BoundField DataField ="RegularisedExtent" HeaderText ="RegularisedExtent"
SortExpression ="RegularisedExtent"/>
< asp:BoundField DataField ="ChallanNo.& Date"
HeaderText ="ChallanNo.& Date" SortExpression ="ChallanNo.& Date"/>
< asp:BoundField DataField ="Endorsement& Date"
HeaderText ="Endorsement& Date" SortExpression ="Endorsement& Date"/>
< footerstyle backcolor =#5D7B9D" font-bold ="True" forecolor ="White">
< pagerstyle backcolor =#284775" forecolor ="White" horizontalalign ="Center">
< SelectedRowStyle BackColor =#E2DED6" Font-Bold ="True" ForeColor =#333333"/>
< HeaderStyle BackColor =#5D7B9D" Font-Bold ="True" ForeColor ="White"/>
< editrowstyle backcolor =#999999">
< alternatingrowstyle backcolor ="White" forecolor =#284775">
[edit]Code moved from comment to question - OriginalGriff[/edit]
<asp:Parameter Name="column2" Type="String" />
<asp:Parameter Name="column3" Type="String" />
<asp:Parameter Name="Village" Type="String" />
<asp:Parameter Name="Mandal" Type="String" />
<asp:Parameter Name="District" Type="String" />
<asp:Parameter Name="RegularisedExtent" Type="String" />
<asp:Parameter Name="column4" Type="String" />
<asp:Parameter DbType="Date" Name="column5" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="S.I.N.O" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<rowstyle backcolor="#F7F6F3" forecolor="#333333">
<columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="S.I.N.O" HeaderText="S.I.N.O" InsertVisible="False"
ReadOnly="True" SortExpression="S.I.N.O" />
<asp:BoundField DataField="NameOfTheApplicant&Address"
HeaderText="NameOfTheApplicant&Address"
SortExpression="NameOfTheApplicant&Address" />
<asp:BoundField DataField="PlotNo." HeaderText="PlotNo."
SortExpression="PlotNo." />
<asp:BoundField DataField="Sy.No" HeaderText="Sy.No" SortExpression="Sy.No" />
<asp:BoundField DataField="Village" HeaderText="Village"
SortExpression="Village" />
<asp:BoundField DataField="Mandal" HeaderText="Mandal"
SortExpression="Mandal" />
<asp:BoundField DataField="District" HeaderText="District"
SortExpression="District" />
<asp:BoundField DataField="RegularisedExtent" HeaderText="RegularisedExtent"
SortExpression="RegularisedExtent" />
<asp:BoundField DataField="ChallanNo.&Date"
HeaderText="ChallanNo.&Date" SortExpression="ChallanNo.&Date" />
<asp:BoundField DataField="Endorsement&Date"
HeaderText="Endorsement&Date" SortExpression="Endorsement&Date" />
<footerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White">
<pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Center">
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<editrowstyle backcolor="#999999">
<alternatingrowstyle backcolor="White" forecolor="#284775">
[edit]Code moved from comment to question - OriginalGriff[/edit]
这篇关于DatagridView更新和插入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!