SelectCommand="SELECT [BUG PRIORITY] as BUG_PRIORITY,[BUG TYPE] as [BUG_TYPE],[BUG TIME] as BUG_TIME,[SOL PRIORITY] as SOL_PRIORITY,[ATTACHMENT],[BUG DESCRIPTION] as BUG_DISCRIPTION,[REMARK],[BUG ID] as BUG_ID FROM [BUG]"
UpdateCommand="UPDATE [BUG] set [BUG PRIORITY]=@BUG_PRIORITY,[BUG TYPE]=@BUG_TYPE,[BUG TIME]=@BUG_TIME,[SOL PRIORITY]=@SOL_PRIORITY,[ATTACHMENT]=@ATTACHMENT,[BUG DESCRIPTION]=@BUG_DISCRIPTION,[REMARK]=@REMARK where [BUG ID]=@BUG_ID
neetu kadyan
Member
1 Points
10 Posts
UPDATE ERROR IN GRID VIEW
Feb 08, 2013 03:55 PM|LINK
HI,
I HAVE USE THE GRID VIEW ,WHEN I CLICK ON THE UPDATE BUTTON ,I GOT THIS ERROR:
Incorrect syntax near 'nvarchar'.
Must declare the scalar variable "@BUG".
AND THIS MY .ASPX CODE:
<asp:templatefield HeaderText ="Options">
<itemtemplate >
<asp:linkbutton id="btnEdit" runat="server" commandname="Edit" text="Edit" />
<asp:linkbutton id="btnDelete" runat="server" commandname="Delete" text="Delete" />
</itemtemplate>
<edititemtemplate>
<asp:linkbutton id="btnUpdate" runat="server" commandname="Update" text="Update" />
<asp:linkbutton id="btnCancel" runat="server" commandname="Cancel" text="Cancel" />
</edititemtemplate>
</asp:templatefield>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [BUG]"
UpdateCommand="UPDATE [Bug] set [BUG PRIORITY] = '@BUG PRIORITY',[BUG TYPE]='@BUG TYPE',[BUG TIME]='@BUG TIME',[SOL PRIORITY]='@SOL PRIORITY',[ATTACHMENT]='@ATTACHMENT',[BUG DESCRIPTION]='@BUG DISCRIPTION',[REMARK]='@REMARK' where [BUG ID]='@BUG ID'">
<UpdateParameters>
<asp:Parameter Name="BUG PRIORITY" Type= "String" />
<asp:Parameter Name="BUG TYPE" Type="String" />
<asp:Parameter Name="BUG TIME" Type="String" />
<asp:Parameter Name="SOL PRIORITY" Type="String" />
<asp:Parameter Name="ATTACHMENT" Type="String" />
<asp:Parameter Name="BUG DESCRIPTION" Type="String" />
<asp:Parameter Name="BUG ID" Type="Int32" />
<asp:Parameter Name="REMARK" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
PLEASE REPLY..
THANK YOU....
MetalAsp.Net
All-Star
112032 Points
18231 Posts
Moderator
Re: UPDATE ERROR IN GRID VIEW
Feb 08, 2013 04:51 PM|LINK
Don't use space character fire your parameter names. Use an underscore instead. See if that makes a difference.
rameps
Member
292 Points
153 Posts
Re: UPDATE ERROR IN GRID VIEW
Feb 08, 2013 05:07 PM|LINK
metal is good.please try it
SelectCommand="SELECT * FROM [BUG]"
UpdateCommand="UPDATE [Bug] set [BUGPRIORITY] = '@BUGPRIORITY',[BUGTYPE]='@BUGTYPE',[BUGTIME]='@BUGTIME',[SOL PRIORITY]='@SOLPRIORITY',[ATTACHMENT]='@ATTACHMENT',[BUGDESCRIPTION]='@BUGDISCRIPTION',[REMARK]='@REMARK' where [BUGID]='@BUGID'">
<UpdateParameters>
<asp:Parameter Name="@BUGPRIORITY" Type= "String" />
<asp:Parameter Name="@BUGTYPE" Type="String" />
<asp:Parameter Name="@BUGTIME" Type="String" />
<asp:Parameter Name="@SOLPRIORITY" Type="String" />
<asp:Parameter Name="@ATTACHMENT" Type="String" />
<asp:Parameter Name="@BUGDESCRIPTION" Type="String" />
<asp:Parameter Name="@BUGID" Type="Int32" />
<asp:Parameter Name="@REMARK" Type="String" />
oned_gk
All-Star
30979 Points
6338 Posts
Re: UPDATE ERROR IN GRID VIEW
Feb 09, 2013 12:01 AM|LINK
1. Make aliases for the field name with space in your select command
2. And use the aliases in your gridview like
datatextfield="BUG_PRIORITY" or BIND("BUG_PRIORITY")3. Use update parameter name same with the aliases
4. Dont use quote for the parameter in update command
neetu kadyan
Member
1 Points
10 Posts
Re: UPDATE ERROR IN GRID VIEW
Feb 09, 2013 06:37 AM|LINK
THANKS FOR THE REPLY.
THE ERROR IS SOLVED BY YOUR ANSEWRS,BUT A NEW ERROR HAS OCCURED:
Incorrect syntax near 'int'.
Must declare the scalar variable "@BUG_DISCRIPTION".
I HAVE MADE THE CHANGES IN THE CODE AS YOU HAVE SUGGESTED,THE CODE IS NOW:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="BUG _ID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="BUG_PRIORITY" HeaderText="BUG_PRIORITY"
SortExpression="BUG_PRIORITY" />
<asp:BoundField DataField="BUG_TYPE" HeaderText="BUG_TYPE"
SortExpression="BUG_TYPE" />
<asp:BoundField DataField="BUG_TIME" HeaderText="BUG_TIME"
SortExpression="BUG_TIME" />
<asp:BoundField DataField="SOL_PRIORITY" HeaderText="SOL_PRIORITY"
SortExpression="SOL_PRIORITY" />
<asp:BoundField DataField="ATTACHMENT" HeaderText="ATTACHMENT"
SortExpression="ATTACHMENT" />
<asp:BoundField DataField="BUG_DESCRIPTION" HeaderText="BUG_DESCRIPTION"
SortExpression="BUG_DESCRIPTION" />
<asp:BoundField DataField="BUG _ID" HeaderText="BUG _ID" InsertVisible="False"
ReadOnly="True" SortExpression="BUG _ID" />
<asp:BoundField DataField="Remark" HeaderText="Remark"
SortExpression="Remark" />
<asp:templatefield HeaderText ="Options">
<itemtemplate >
<asp:linkbutton id="btnEdit" runat="server" commandname="Edit" text="Edit" />
<asp:linkbutton id="btnDelete" runat="server" commandname="Delete" text="Delete" />
</itemtemplate>
<edititemtemplate>
<asp:linkbutton id="btnUpdate" runat="server" commandname="Update" text="Update" />
<asp:linkbutton id="btnCancel" runat="server" commandname="Cancel" text="Cancel" />
</edititemtemplate>
</asp:templatefield>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [BUG]"
UpdateCommand="UPDATE [BUG] set [BUG_PRIORITY]=BUG_PRIORITY,[BUG_TYPE]=@BUG_TYPE,[BUG_TIME]=@BUG_TIME,[SOL_PRIORITY]=@SOL_PRIORITY,[ATTACHMENT]=@ATTACHMENT,[BUG_DESCRIPTION]=@BUG_DISCRIPTION,[REMARK]=@REMARK where [BUG_ID]=@BUG_ID">
<UpdateParameters>
<asp:Parameter Name="BUG_PRIORITY" Type= "String" />
<asp:Parameter Name="BUG_TYPE" Type="String" />
<asp:Parameter Name="BUG_TIME" Type="String" />
<asp:Parameter Name="SOL_PRIORITY" Type="String" />
<asp:Parameter Name="ATTACHMENT" Type="String" />
<asp:Parameter Name="BUG_DESCRIPTION" Type="String" />
<asp:Parameter Name="BUG_ID" Type="Int32"/>
<asp:Parameter Name="REMARK" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
I NEED YOUR HELP SO PLEASE REPLY.
THANK YOU...
oned_gk
All-Star
30979 Points
6338 Posts
Re: UPDATE ERROR IN GRID VIEW
Feb 09, 2013 07:03 AM|LINK
oned_gk
All-Star
30979 Points
6338 Posts
Re: UPDATE ERROR IN GRID VIEW
Feb 09, 2013 07:06 AM|LINK
If you confusing about the fieldname and aliases, simply dont use space for field names.
Redesign your table.
Or use wizard to create sqldatasource, check autogenerate UPDATE,INSERT,DELETE
mbanavige
All-Star
134944 Points
15413 Posts
ASPInsiders
Moderator
MVP
Re: UPDATE ERROR IN GRID VIEW
Feb 09, 2013 12:08 PM|LINK
you have a typo in your code... you parameter name is spelled like this: BUG_DESCRIPTION
but your query is looking for this: BUG_DISCRIPTION
oned_gk
All-Star
30979 Points
6338 Posts
Re: UPDATE ERROR IN GRID VIEW
Feb 09, 2013 12:43 PM|LINK
neetu kadyan
Member
1 Points
10 Posts
Re: UPDATE ERROR IN GRID VIEW
Feb 09, 2013 12:45 PM|LINK
THANK YOU.YES YOU ARE RIGHT.
BUT NOW ANOTHER EXCEPTION HAS OCCURED.
PLEASE REPLY.THANK YOU...