Answered by:
ASP.NET GridView not updating with bound adapter

Question
-
Hi I'm new to ASP.NET programming and I'm looking to update a bound data source (SQL Server) using a GridView control linked to a data set. In the dataset.xsd file I've added an sql query to the table adapter and configured the GridView to call this adapter. But when I run it the program runs but any changes that are made to the GridView simply revert back to the original data.
could anyone help with this? I think the problem may lie in the way i have configured the update method of the table adapter.
The source code from default.aspx is listed below;
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="MyFirstWebApp._default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<p>
Sample No <asp:TextBox ID="SampleNo1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="Submit1" runat="server" Height="26px" OnClick="Submit1_Click" Text="Submit" Width="83px" />
</p>
<p>
</p>
<p>
<asp:Label ID="OutputLabel1" runat="server"></asp:Label>
</p>
<p>
</p>
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="ObjectDataSource1" DataTextField="Sample_Type" DataValueField="Sample_Type">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetSampleType" TypeName="MyFirstWebApp.App_Code.DataSet2TableAdapters.SampleTypesTableAdapter"></asp:ObjectDataSource>
<br />
SF
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="MyFirstWebApp.App_Code.DataSet2TableAdapters.SamplesTableAdapter" UpdateMethod="UpdateTabQuery">
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Hospital_Number" Type="Int32" />
<asp:Parameter Name="Sample_Number" Type="String" />
<asp:Parameter Name="Sample_Type" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="SampleType" PropertyName="SelectedValue" Type="String" DefaultValue="red" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Sample_Number" Type="String" />
<asp:Parameter Name="Hospital_Number" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Sample_type" Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
<br />
<br />
<asp:ObjectDataSource ID="ObjectDataSource4" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetSamples" TypeName="MyFirstWebApp.App_Code.DataSet2TableAdapters.PaitentSamplesTableAdapter"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server"></asp:ObjectDataSource>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource5">
<Columns>
<asp:BoundField DataField="Sample_Number" HeaderText="Sample_Number" SortExpression="Sample_Number" />
</Columns>
</asp:GridView>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="ObjectDataSource2">
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Hospital_Number" HeaderText="Hospital_Number" SortExpression="Hospital_Number" />
<asp:BoundField DataField="Sample_Number" HeaderText="Sample_Number" SortExpression="Sample_Number" />
<asp:BoundField DataField="Sample_Type" HeaderText="Sample_Type" SortExpression="Sample_Type" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource6" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="DataSet2TableAdapters.SamplesTableAdapter" UpdateMethod="UpdateTabQuery">
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Hospital_Number" Type="Int32" />
<asp:Parameter Name="Sample_Number" Type="String" />
<asp:Parameter Name="Sample_Type" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:Parameter Name="SampleType" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Sample_Number" Type="String" />
<asp:Parameter Name="Hospital_Number" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Sample_type" Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource5" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetSamples" TypeName="DataSet2TableAdapters.PaitentSamplesTableAdapter"></asp:ObjectDataSource>
<br />
<br />
<br />
<br />
<br />
<br />
</form>
</body>
</html>
- Moved by Bob Wu-MT Thursday, February 21, 2013 5:02 AM
Wednesday, February 20, 2013 1:37 PM
Answers
-
You should post this question to ASP.NET Data Controls forum as this forum relates to Windows Forms data controls.Wednesday, February 20, 2013 1:42 PM