C# .NET - while updating items in gridview am getting Illgean Name/variable But Psno,type,cmmi,itctm belongs to varchar type and sysno belong to number how do i update it pl check my code

Asked By Lalitha Kumaran on 23-May-08 05:47 AM

<%@ Page Language="C#" %>

<html>

<head id="Head1" runat="server">

<title>Updating Data Using GridView</title>

</head>

<body>

<form id="form1" runat="server">

<asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" PagerStyle-HorizontalAlign="Center" Runat="server" Caption="Edit Your Details" CaptionAlign="Top" CellPadding="3" CellSpacing="0" Width="60%"

DataSourceID="SqlDataSource1" AutoGenerateEditButton="True"

AutoGenerateColumns="False" DataKeyNames="PSNO">

<Columns>

<asp:BoundField ReadOnly="true" HeaderText="PSNO" DataField="PSNO" SortExpression="PSNO" />

<asp:BoundField HeaderText="System No" DataField="SYSNO" SortExpression="SYSNO" />

<asp:BoundField HeaderText="PC/Workstation(P/W)" DataField="TYPE" SortExpression="TYPE" />

<asp:BoundField HeaderText="CMMI-CTM" DataField="CMMI" SortExpression="CMMI"/>

<asp:BoundField HeaderText="IT-CTM" DataField="ITCTM" SortExpression="ITCTM"/>

</Columns>

</asp:GridView>

&nbsp;

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT "PSNO", "SYSNO", "TYPE", "CMMI", "ITCTM" FROM "SYS_NO" ORDER BY "ROLE", "SYSNO"'

UpdateCommand="UPDATE [SYS_NO] SET [SYSNO] = @SYSNO">


</asp:SqlDataSource>

&nbsp;

</form>

</body>

</html>

you need to add parameters Collection for Datasource.... - Vasanthakumar D replied to Lalitha Kumaran on 23-May-08 06:12 AM

Hi,

you need to add the parameter colllection  to your datasource like the below one...

<asp:SqlDataSource ID="ProductsDataSource" runat="server" ConnectionString="..."
   SelectCommand="SELECT [ProductID], [ProductName], [Products].[CategoryID], [CategoryName], [UnitPrice], [Discontinued] FROM [Products] INNER JOIN [Categories] ON [Products].[CategoryID] = [Categories].[CategoryID] ORDER BY [ProductName]"
   UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID, [UnitPrice] = @UnitPrice, [Discontinued] = @Discontinued WHERE [ProductID] = @ProductID">
   <UpdateParameters>
      <asp:Parameter Name="ProductName" Type="String" />
      <asp:Parameter Name="CategoryID" Type="Int32" />
      <asp:Parameter Name="UnitPrice" Type="Decimal" />
      <asp:Parameter Name="Discontinued" Type="Boolean" />
      <asp:Parameter Name="ProductID" Type="Int32" />
   </UpdateParameters>

</asp:SqlDataSource>

 

check the below for more details..

http://aspnet.4guysfromrolla.com/articles/080107-1.aspx

Sunil Lakshkar replied to Lalitha Kumaran on 23-May-08 06:14 AM

HI,

Add update parameter after updateCommand


UpdateCommand="UPDATE [SYS_NO] SET [SYSNO] = @SYSNO">

<UpdateParameters>
<asp:Parameter Name="SYSNO" Type="String" />
</UpdateParameters>

Try this - Nadaraja Yogendran replied to Lalitha Kumaran on 23-May-08 06:25 AM

UpdateCommand="UPDATE [SYS_NO] SET [SYSNO] = @SYSNO WHERE [PSNO] = @PSNO"

Hi, - sri sri replied to Lalitha Kumaran on 23-May-08 07:01 AM
end of post
check this - sri sri replied to Lalitha Kumaran on 23-May-08 07:02 AM
Hi,
you are missing the parameters

add this in your code
  <UpdateParameters>
      <asp:Parameter Name="ProductName" Type="String" />
      <asp:Parameter Name="CategoryID" Type="Int32" />
      <asp:Parameter Name="UnitPrice" Type="Decimal" />
      <asp:Parameter Name="Discontinued" Type="Boolean" />
      <asp:Parameter Name="ProductID" Type="Int32" />
   </UpdateParameters>