B
Brad Baker
I have a formview with a datasource that contains a select and update
command. The select statement works fine but the update command doesn't seem
to be working. After some troubleshooting I have narrowed the problem down
to the department_id parameter which is set from a hidden field.
I can confirm this by hard coding the UpdateCommand to: UPDATE configuration
SET special_notes=@special_notes WHERE (student_id=@student_id) AND
(department_id='1234'). I know my hidden field is getting set correctly
because I am do a "view source" on the rendered page and see the department
id being set with no extra spaces, correct case and so forth. Could someone
help me figure out what I am missing?
Thanks,
Brad
<asp:SqlDataSource ID="formview_datasource" runat="server"
ConnectionString="Connection Info" ProviderName="System.Data.SqlClient"
SelectCommand="select command" UpdateCommand="UPDATE configuration SET
special_notes=@special_notes WHERE (student_id=@student_id) AND
(department_id=@department_id)" OnSelecting="SetParameters">
<SelectParameters>
<asp:QueryStringParameter Name="student_id"
QueryStringField="student_id" Type="String" />
<asparameter Name="department_id" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:FormParameter FormField="student_id" Name="student_id" />
<asp:FormParameter FormField="department_id" Name="department_id" />
<asp:FormParameter FormField="special_notes" Name="special_notes" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:FormView ID="formview" runat="server"
DataSourceID="formview_datasource" Width="100%">
<EditItemTemplate>
<table>
<tr>
<td class="right_labels">Special Notes:</td>
<td colspan="3" > <asp:TextBox ID="special_notes" runat="server"
rows="5" style="width: 85%" Text='<%# Bind("special_notes") %>'
TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" />
<asp:HiddenField ID="student_id" Value='<%#
Bind("student_id") %>' runat="server" />
<asp:Button ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update" Text="Update"> </asp:Button>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
command. The select statement works fine but the update command doesn't seem
to be working. After some troubleshooting I have narrowed the problem down
to the department_id parameter which is set from a hidden field.
I can confirm this by hard coding the UpdateCommand to: UPDATE configuration
SET special_notes=@special_notes WHERE (student_id=@student_id) AND
(department_id='1234'). I know my hidden field is getting set correctly
because I am do a "view source" on the rendered page and see the department
id being set with no extra spaces, correct case and so forth. Could someone
help me figure out what I am missing?
Thanks,
Brad
<asp:SqlDataSource ID="formview_datasource" runat="server"
ConnectionString="Connection Info" ProviderName="System.Data.SqlClient"
SelectCommand="select command" UpdateCommand="UPDATE configuration SET
special_notes=@special_notes WHERE (student_id=@student_id) AND
(department_id=@department_id)" OnSelecting="SetParameters">
<SelectParameters>
<asp:QueryStringParameter Name="student_id"
QueryStringField="student_id" Type="String" />
<asparameter Name="department_id" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:FormParameter FormField="student_id" Name="student_id" />
<asp:FormParameter FormField="department_id" Name="department_id" />
<asp:FormParameter FormField="special_notes" Name="special_notes" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:FormView ID="formview" runat="server"
DataSourceID="formview_datasource" Width="100%">
<EditItemTemplate>
<table>
<tr>
<td class="right_labels">Special Notes:</td>
<td colspan="3" > <asp:TextBox ID="special_notes" runat="server"
rows="5" style="width: 85%" Text='<%# Bind("special_notes") %>'
TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" />
<asp:HiddenField ID="student_id" Value='<%#
Bind("student_id") %>' runat="server" />
<asp:Button ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update" Text="Update"> </asp:Button>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>