Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update gridview issue

Status
Not open for further replies.

auchtum

Programmer
Nov 21, 2008
20
0
0
US
When I click in the update link and try to save then, is not saving anything at all. How can I solve this update issue with my gridview?



This is my code:


<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="SqlDataProspecto" DataKeyNames="IdProspecto" Style="position: static">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="IdProspecto" HeaderText="IdProspecto" InsertVisible="False"
ReadOnly="True" SortExpression="IdProspecto" />
<asp:BoundField DataField="Prospecto" HeaderText="Prospecto" SortExpression="Prospecto" />
<asp:TemplateField HeaderText="Sector" SortExpression="Descripcion">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSector"
DataTextField="Descripcion" DataValueField="IdSector" SelectedValue='<%# Bind("IdSector") %>'
Style="position: static">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSector" runat="server" ConnectionString="<%$ ConnectionStrings:SIPConnectionString %>"
SelectCommand="SELECT * FROM [Sector] ORDER BY [Descripcion]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Descripcion") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nicho" SortExpression="Nicho">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataNicho" DataTextField="Descripcion"
DataValueField="IdNicho" SelectedValue='<%# Bind("IdNicho") %>' Style="position: static">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataNicho" runat="server" ConnectionString="<%$ ConnectionStrings:SIPConnectionString %>"
SelectCommand="SELECT * FROM [Nicho] ORDER BY [Descripcion]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Nicho") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataProspecto" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:SIPConnectionString %>" DeleteCommand="DELETE FROM [Prospecto] WHERE [IdProspecto] = @original_IdProspecto AND [Nombre] = @original_Nombre AND [IdSector] = @original_IdSector AND [IdNicho] = @original_IdNicho"
InsertCommand="INSERT INTO [Prospecto] ([Nombre], [IdSector], [IdNicho]) VALUES (@Nombre, @IdSector, @IdNicho)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT Prospecto.IdProspecto, Prospecto.Nombre AS Prospecto, Sector.IdSector, Sector.Descripcion, Nicho.IdNicho, Nicho.Descripcion AS Nicho FROM Prospecto INNER JOIN Sector ON Prospecto.IdSector = Sector.IdSector INNER JOIN Nicho ON Prospecto.IdNicho = Nicho.IdNicho ORDER BY Prospecto"
UpdateCommand="UPDATE [Prospecto] SET [Nombre] = @Nombre, [IdSector] = @IdSector, [IdNicho] = @IdNicho WHERE [IdProspecto] = @original_IdProspecto AND [Nombre] = @original_Nombre AND [IdSector] = @original_IdSector AND [IdNicho] = @original_IdNicho">
<DeleteParameters>
<asp:parameter Name="original_IdProspecto" Type="Int16" />
<asp:parameter Name="original_Nombre" Type="String" />
<asp:parameter Name="original_IdSector" Type="Int16" />
<asp:parameter Name="original_IdNicho" Type="Int16" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Nombre" Type="String" />
<asp:parameter Name="IdSector" Type="Int16" />
<asp:parameter Name="IdNicho" Type="Int16" />
<asp:parameter Name="original_IdProspecto" Type="Int16" />
<asp:parameter Name="original_Nombre" Type="String" />
<asp:parameter Name="original_IdSector" Type="Int16" />
<asp:parameter Name="original_IdNicho" Type="Int16" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Nombre" Type="String" />
<asp:parameter Name="IdSector" Type="Int16" />
<asp:parameter Name="IdNicho" Type="Int16" />
</InsertParameters>
</asp:SqlDataSource>



Thanks in advance for the support.
 
Thanks for your post, but that's a different issue, the situation here is realted with the updatecommand in my gridview, becuase with deletecommand it works.
 
I found the solution.

I just changed:
UpdateCommand="UPDATE [Prospecto] SET [Nombre] = @Nombre, [IdSector] = @IdSector, [IdNicho] = @IdNicho WHERE [IdProspecto] = @original_IdProspecto">

For this:

UpdateCommand="UPDATE [Prospecto] SET [Nombre] = @Prospecto, [IdSector] = @IdSector, [IdNicho] = @IdNicho WHERE [IdProspecto] = @original_IdProspecto">
 
I still strongly suggest you stop using the datasource controls. You CANNOT debug them when you have a problem such as this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top