473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Update command not working with hidden field as a parameter

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" />
<asp:Parameter 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>
Jun 4 '07 #1
3 4771
Hello Brad,

From your description, you're encountering some problem when using FormView
with some update parameter reference to HiddenField control ,correct?

As for the updating command, what's the exact problem behavior, is there
any error message such as "parameter is not supplied or method signature
not match"?

Based on the aspx template you provided, you've the following
EditTemplate(used for updating command)

===============
<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>
===================

Only "special_notes" and "student_id" is supplied through "Bind" keyword in
binding expression. however, the update parameters in DataSource control
expected three parameters:

================
<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>
====================

and the <asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" /doesn't seem to be a
valid two-way databinding expression.

Also, I have tried a very simple test with FormView edittemplate using a
HiddenField to reference a primary key column (in database table) and the
updating can work correctly.

You can check the above setting or try a simplified table to see whether
the parameters and binding expression setting is the cause.

If there is any other finding, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 5 '07 #2
><asp:HiddenField ID="department_id" Value='<%#
>Department.GetDepartmentID() %>' runat="server" /doesn't seem to be a
valid two-way databinding expression.
I wasn't trying to update the department_id value, only use it as a SQL
WHERE criteria. Apparently even though I don't want to update it, a two way
databinding expression was what I needed. When I changed the above to read:

<asp:HiddenField ID="department_id" Value='<%# Bind("department_id") %>'
runat="server" />

Everything started to work as I expected.

Thank you! :-)
Brad
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:R6**************@TK2MSFTNGHUB02.phx.gbl...
Hello Brad,

From your description, you're encountering some problem when using
FormView
with some update parameter reference to HiddenField control ,correct?

As for the updating command, what's the exact problem behavior, is there
any error message such as "parameter is not supplied or method signature
not match"?

Based on the aspx template you provided, you've the following
EditTemplate(used for updating command)

===============
<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>
===================

Only "special_notes" and "student_id" is supplied through "Bind" keyword
in
binding expression. however, the update parameters in DataSource control
expected three parameters:

================
<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>
====================

and the <asp:HiddenField ID="department_id" Value='<%#
Department.GetDepartmentID() %>' runat="server" /doesn't seem to be a
valid two-way databinding expression.

Also, I have tried a very simple test with FormView edittemplate using a
HiddenField to reference a primary key column (in database table) and the
updating can work correctly.

You can check the above setting or try a simplified table to see whether
the parameters and binding expression setting is the cause.

If there is any other finding, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 5 '07 #3
You're welcome :)

Have a nice day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave Smithz | last post by:
Hi there, Working on the PHP DB I took over I have just come across a problem. When the user presses refresh in some circumstances the command they just performed will be re-performed. In some...
5
by: Jason Huang | last post by:
Hi, The SqlParameter myPM =new SqlParameter("@Address", txtAddress.Text) is working for update, but SqlParameter myPM =new SqlParameter ("@Address",SqlDbType.NVarChar,90,txtAddress.Text) is...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
0
by: troyblakely | last post by:
I have a gridview which is pulling data from a SqlDataSource, the select command queries a view and the update command is a stored procedure. I'm using a stored procedure because several tables...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.