INSERTING in DetailsView doesn't work, eventhough UPDATE does

BestyMerryBMW

New Member
I have a DetailsView that lets me successfully page through and edit the records in an Access database. But, when I try to use the same data binding to insert a new record in that table, something very strange happens -- all of the fields get written to the database EXCEPT for one bound field, which in turn prevents the record from showing up in the DetailsView. Here's the relevant code:\[code\]<asp:AccessDataSource ID="CurrentNotes" runat="server" DataFile="C:\Users\tetewssj\Documents\Sample\App_Data\RSI_Data.mdb" SelectCommand="SELECT * FROM [ProgressNotes], [Programs] WHERE ([CustomerID] = AND [ProgressNotes.Program] = [Programs.ProgramCode]) ORDER BY [ServDate] DESC" InsertCommand="INSERT INTO [PROGRESSNOTES] ([CustomerID], [ServDate], [NoteDate], [TimeSpent], [StaffID], [Program], [Progress]) VALUES (?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE ProgressNotes SET ServDate=?, NoteDate=?, TimeSpent=?, StaffID=?, Program=?, Progress=? WHERE Entry=?"> <SelectParameters> <asp:ControlParameter ControlID="CustID" Name="CustomerID" PropertyName="Text" Type="String" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="CustomerID" Type="String" /> <asp:Parameter Name="ServDate" Type="String" /> <asp:Parameter Name="NoteDate" Type="String" /> <asp:Parameter Name="TimeSpent" Type="String"/> <asp:Parameter Name="StaffID" Type="String" /> <asp:Parameter Name="Program" Type="String" /> <asp:Parameter Name="Progress" Type="String" /> </InsertParameters> </asp:AccessDataSource> <asp:DetailsView ID="ViewNotes" runat="server" Height="50px" Width="326px" DataKeyNames="Entry" AutoGenerateRows="False" DataSourceID="CurrentNotes" AllowPaging="True"> <AlternatingRowStyle BorderStyle="None" BorderWidth="1px" /> <FieldHeaderStyle HorizontalAlign="Right" BorderStyle="None" /> <Fields> <asp:BoundField HeaderText="Customer :" DataField="CustomerID" SortExpression="CustomerID" ReadOnly="True"> </asp:BoundField> <asp:BoundField HeaderText="Service date :" DataField="ServDate" SortExpression="ServDate" DataFormatString="{0:d}" HtmlEncode="False"> </asp:BoundField> --- skipping to the offending field, Program. The EditItemTemplate --- works fine, but the InsertItemTemplate doesn't work <asp:TemplateField HeaderText="Program :" SortExpression="Program"> <EditItemTemplate> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\Users\tetewssj\Documents\Sample\App_Data\RSI_Data.mdb"" ProviderName="System.Data.OleDb" SelectCommand="SELECT * FROM [Programs]"> </asp:SqlDataSource> <asp:RadioButtonList ID="RadioButtonList2" runat="server" DataSourceID="SqlDataSource1" DataTextField="Program_abbrev" DataValueField="ProgramCode" SelectedValue='http://stackoverflow.com/questions/12698901/<%# Bind("ProgramCode") %>'> </asp:RadioButtonList> </EditItemTemplate> <InsertItemTemplate> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\Users\tetewssj\Documents\Sample \App_Data\RSI_Data.mdb"" ProviderName="System.Data.OleDb" SelectCommand="SELECT * FROM [Programs]"> </asp:SqlDataSource> <asp:RadioButtonList ID="RadioButtonList3" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Program_abbrev" DataValueField="ProgramCode" SelectedValue='http://stackoverflow.com/questions/12698901/<%# Bind("ProgramCode", "{0}") %>'> </asp:RadioButtonList> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("Program_abbrev") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> --- skipping the other fields that work just fine</asp:DetailsView>\[/code\]In summary, the radio button list that shows Program abbreviations (e.g. ACE, UCS) corresponding to integer values (1, 2 etc) works fine in editing more, but doesn't work for inserting a new record. When I click on the insert link, all fields write to the database EXCEPT for ProgramCode. If I replace that radio button list with a simple text field that accepts an integer, then the INSERT works just fine. Also, note that DataKeyNames="Entry" refers to an autonumber field in the ProgressNotes table, and the corresponding .vb file has no additional functions. This is all done in Visual Studio 2008 Express EditionAny help is greatly appreciated! Thanks
 
Back
Top