Issues with Stongly-Typed ObjectDataSource's UpdateMethod

G

Guest

I really hope this is not a case of "this silly thing will never
work".....lots of time invested in troubleshooting this already.

I have created a standard ASP.NET web form (.aspx) with several collections
of textboxes prompting for entry into a fairly monolithic database. I
decided to create a business object (called Employee) and use the
ObjectDataSource to broker data being transmitted between the UI and my
Employee object (and subsequently the database). This works just great for
reading data into all the fields. But for some reason, and despite from all
appearnaces I'm doing exactly what all the examples suggest one should do,
the Update method (Update()) refuses to update edits made to any of the bound
textboxes. I really need help with this - or very bad things might happen to
me.

Here's the declaration for the ObjectDataSource control on the page:

1 <asp:ObjectDataSource ID="odsEmployeeEdit" runat="server"
SelectMethod="GetEntity"
2 TypeName="GC.Finance.Web500.Data.EmployeeAdapter"
DataObjectTypeName="GC.Finance.Web500.Data.PSEmployee"
3 DeleteMethod="Delete" InsertMethod="Insert"
UpdateMethod="Update">
4 <SelectParameters>
5 <asp:QueryStringParameter Name="id" QueryStringField="empl"
Type="Int32" />
6 </SelectParameters> Notice above that the DataObjectTypeName
is set to the PSEmployee object, thus making this a storngly-typed
ObjectDataSource. (This is the business ojbect described as the "Employee"
object above.) I did fine one example where a strongly-typed
ObjectDataSource was used at
http://msdn2.microsoft.com/en-gb/library/ms227562.aspx.

And just to give you an idea how all the textboxes are bound on the page to
this datasource, I'll include a partial listing from the .aspx file in
question:

1 <asp:FormView ID="frmvwEmployeeMain" DataSourceID="odsEmployeeEdit"
runat="server">
2
3 <ItemTemplate>
4 <table id="tblMainInfo">
5 <tr>
6 <td class="TabArea" valign="top" style="text-align:
left">
7 <uc2:EmployeeOrg ID="EmployeeOrg1"
runat="server" />
8 <table>
9 <tr>
10 <td>
11 <table>
12 <tr>
13 <td style="width: 114px">
14 <asp:Label
ID="lblTitleEn" runat="server" meta:resourcekey="lblTitleEnResource1"
Text="Title (English):"></asp:Label></td>
15 <td colspan="3">
16 <asp:TextBox
ID="txtTitleEn" runat="server" meta:resourcekey="txtTitleEnResource1"
Text='<%# Bind("TitleEnglish") %>'></asp:TextBox></td>
17 </tr>
18 <tr>
19 <td style="height: 26px;
width: 114px;">
20 <asp:Label
ID="lblTitleFr" runat="server" meta:resourcekey="lblTitleFrResource1"
Text="Title (French):"></asp:Label></td>
21 <td colspan="3">
22 <asp:TextBox
ID="txtTitleFr" runat="server" meta:resourcekey="txtTitleFrResource1"
Text='<%# Bind("TitleFrench") %>'></asp:TextBox></td>
23 </tr> So as you can see form
the above, <%# Bind() %> statements referencing the FormView's datasource are
useful for displaying data. But when the Update() method gets called, the
PSEmployee's New() method is invovked, creating an "empty" instance. And,
consequently, when the EmployeeAdapter's Update() method is invoked, the
PSEmployee instance passed therein has no values - nothing is passed in from
the web form:



1 Public Class EmployeeAdapter
2 Inherits DirectoryServicesAdapter
3 Implements IDisposable
4
5 Public Sub New()
6
7 MyBase.New()
8
9 End Sub
10
11 ...
12
13 Public Overrides Function Update(ByVal de As IDirectoryEntity) As
Boolean
14
15 Dim retVal As Boolean = de.Update()
16 Return retVal
17
18 End Function
19
20 Public Overloads Function Update(ByVal empl As PSEmployee) As Boolean
21
22 Return Update(CType(empl, IDirectoryEntity))
23
24 End Function
25
26 ...
27
28 (and so on...) In other words, on line 22 in the listing above, the
empl instance of PSEmployee has empty values, meaning nothing was passed from
the web form.

The error that ultimately results when this code is executed, thus, is simply:

Server Error in '/Update500' Application.
--------------------------------------------------------------------------------

Procedure 'sp_EmployeeUpdate' expects parameter '@surname', which was not
supplied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Procedure
'sp_EmployeeUpdate' expects parameter '@surname', which was not supplied.

Source Error:

Line 31: Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
Line 32:
Line 33: _dso.Update()
Line 34:
Line 35: End Sub

Source File: c:\inetpub\wwwroot\Update500\UserControls\EmployeeCRUD.ascx.vb
Line: 33

Stack Trace:

[SqlException (0x80131904): Procedure 'sp_EmployeeUpdate' expects parameter
'@surname', which was not supplied.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection) +857338
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) +734950

System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
+886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe) +415
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
GC.Finance.Web500.Data.PSEmployee.Update() in C:\Documents and
Settings\rholder\My Documents\Visual Studio
2005\Projects\GC.Finance.X500.Data\GC.Finance.X500.Data\Entities\PSEmployee.vb:211
GC.Finance.Web500.Data.EmployeeAdapter.Update(IDirectoryEntity de) in
C:\Documents and Settings\rholder\My Documents\Visual Studio
2005\Projects\GC.Finance.X500.Data\GC.Finance.X500.Data\Adapters\EmployeeAdapter.vb:80
GC.Finance.Web500.Data.EmployeeAdapter.Update(PSEmployee empl) in
C:\Documents and Settings\rholder\My Documents\Visual Studio
2005\Projects\GC.Finance.X500.Data\GC.Finance.X500.Data\Adapters\EmployeeAdapter.vb:87

NOTE: I have also tried adding a DataKeyNames property ("ID", the index
property for the Employee business object) to the FormView control; which has
had no impact on this issue.

Really need help with this one - thanks for any and all assistance!

Appreciatively,
 
G

gerry

Hi Ross,

I just went through this same process for the 1st time using GridView &
DetailsView with no problems - I have not tried the FormView.

What does your PSEmployee class look like - specifically property
declarations & Update method ?
Why are you handling the Button.Click event & what is the _dso that it is
referring to , should it actually be odsEmployeeEdit ?

1st check - PSEmployee bindable values are defined as public properties and
not fields.
2nd check - verify that PSEmployee.Update is building the update command
properly

Gerry


ross613 said:
I really hope this is not a case of "this silly thing will never
work".....lots of time invested in troubleshooting this already.

I have created a standard ASP.NET web form (.aspx) with several
collections
of textboxes prompting for entry into a fairly monolithic database. I
decided to create a business object (called Employee) and use the
ObjectDataSource to broker data being transmitted between the UI and my
Employee object (and subsequently the database). This works just great
for
reading data into all the fields. But for some reason, and despite from
all
appearnaces I'm doing exactly what all the examples suggest one should do,
the Update method (Update()) refuses to update edits made to any of the
bound
textboxes. I really need help with this - or very bad things might happen
to
me.

Here's the declaration for the ObjectDataSource control on the page:

1 <asp:ObjectDataSource ID="odsEmployeeEdit" runat="server"
SelectMethod="GetEntity"
2 TypeName="GC.Finance.Web500.Data.EmployeeAdapter"
DataObjectTypeName="GC.Finance.Web500.Data.PSEmployee"
3 DeleteMethod="Delete" InsertMethod="Insert"
UpdateMethod="Update">
4 <SelectParameters>
5 <asp:QueryStringParameter Name="id"
QueryStringField="empl"
Type="Int32" />
6 </SelectParameters> Notice above that the DataObjectTypeName
is set to the PSEmployee object, thus making this a storngly-typed
ObjectDataSource. (This is the business ojbect described as the
"Employee"
object above.) I did fine one example where a strongly-typed
ObjectDataSource was used at
http://msdn2.microsoft.com/en-gb/library/ms227562.aspx.

And just to give you an idea how all the textboxes are bound on the page
to
this datasource, I'll include a partial listing from the .aspx file in
question:

1 <asp:FormView ID="frmvwEmployeeMain" DataSourceID="odsEmployeeEdit"
runat="server">
2
3 <ItemTemplate>
4 <table id="tblMainInfo">
5 <tr>
6 <td class="TabArea" valign="top"
style="text-align:
left">
7 <uc2:EmployeeOrg ID="EmployeeOrg1"
runat="server" />
8 <table>
9 <tr>
10 <td>
11 <table>
12 <tr>
13 <td style="width: 114px">
14 <asp:Label
ID="lblTitleEn" runat="server" meta:resourcekey="lblTitleEnResource1"
Text="Title (English):"></asp:Label></td>
15 <td colspan="3">
16 <asp:TextBox
ID="txtTitleEn" runat="server" meta:resourcekey="txtTitleEnResource1"
Text='<%# Bind("TitleEnglish") %>'></asp:TextBox></td>
17 </tr>
18 <tr>
19 <td style="height: 26px;
width: 114px;">
20 <asp:Label
ID="lblTitleFr" runat="server" meta:resourcekey="lblTitleFrResource1"
Text="Title (French):"></asp:Label></td>
21 <td colspan="3">
22 <asp:TextBox
ID="txtTitleFr" runat="server" meta:resourcekey="txtTitleFrResource1"
Text='<%# Bind("TitleFrench") %>'></asp:TextBox></td>
23 </tr> So as you can see form
the above, <%# Bind() %> statements referencing the FormView's datasource
are
useful for displaying data. But when the Update() method gets called, the
PSEmployee's New() method is invovked, creating an "empty" instance. And,
consequently, when the EmployeeAdapter's Update() method is invoked, the
PSEmployee instance passed therein has no values - nothing is passed in
from
the web form:



1 Public Class EmployeeAdapter
2 Inherits DirectoryServicesAdapter
3 Implements IDisposable
4
5 Public Sub New()
6
7 MyBase.New()
8
9 End Sub
10
11 ...
12
13 Public Overrides Function Update(ByVal de As IDirectoryEntity) As
Boolean
14
15 Dim retVal As Boolean = de.Update()
16 Return retVal
17
18 End Function
19
20 Public Overloads Function Update(ByVal empl As PSEmployee) As
Boolean
21
22 Return Update(CType(empl, IDirectoryEntity))
23
24 End Function
25
26 ...
27
28 (and so on...) In other words, on line 22 in the listing above, the
empl instance of PSEmployee has empty values, meaning nothing was passed
from
the web form.

The error that ultimately results when this code is executed, thus, is
simply:

Server Error in '/Update500' Application.
--------------------------------------------------------------------------------

Procedure 'sp_EmployeeUpdate' expects parameter '@surname', which was not
supplied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Procedure
'sp_EmployeeUpdate' expects parameter '@surname', which was not supplied.

Source Error:

Line 31: Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
Line 32:
Line 33: _dso.Update()
Line 34:
Line 35: End Sub

Source File:
c:\inetpub\wwwroot\Update500\UserControls\EmployeeCRUD.ascx.vb
Line: 33

Stack Trace:

[SqlException (0x80131904): Procedure 'sp_EmployeeUpdate' expects
parameter
'@surname', which was not supplied.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection) +857338
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) +734950

System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
+886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe) +415
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
GC.Finance.Web500.Data.PSEmployee.Update() in C:\Documents and
Settings\rholder\My Documents\Visual Studio
2005\Projects\GC.Finance.X500.Data\GC.Finance.X500.Data\Entities\PSEmployee.vb:211
GC.Finance.Web500.Data.EmployeeAdapter.Update(IDirectoryEntity de) in
C:\Documents and Settings\rholder\My Documents\Visual Studio
2005\Projects\GC.Finance.X500.Data\GC.Finance.X500.Data\Adapters\EmployeeAdapter.vb:80
GC.Finance.Web500.Data.EmployeeAdapter.Update(PSEmployee empl) in
C:\Documents and Settings\rholder\My Documents\Visual Studio
2005\Projects\GC.Finance.X500.Data\GC.Finance.X500.Data\Adapters\EmployeeAdapter.vb:87

NOTE: I have also tried adding a DataKeyNames property ("ID", the index
property for the Employee business object) to the FormView control; which
has
had no impact on this issue.

Really need help with this one - thanks for any and all assistance!

Appreciatively,

--------------------------------------------------------------------------------
Ross Holder,
Ottawa, ON (Canada)
http://ross613.spaces.msn.com
"The more you know, the more you wanna know more."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top