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
ObjectDataSourc e 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 ObjectDataSourc e control on the page:
1 <asp:ObjectData Source ID="odsEmployee Edit" runat="server"
SelectMethod="G etEntity"
2 TypeName="GC.Fi nance.Web500.Da ta.EmployeeAdap ter"
DataObjectTypeN ame="GC.Finance .Web500.Data.PS Employee"
3 DeleteMethod="D elete" InsertMethod="I nsert"
UpdateMethod="U pdate">
4 <SelectParamete rs>
5 <asp:QueryStrin gParameter Name="id" QueryStringFiel d="empl"
Type="Int32" />
6 </SelectParameter s Notice above that the DataObjectTypeN ame
is set to the PSEmployee object, thus making this a storngly-typed
ObjectDataSourc e. (This is the business ojbect described as the "Employee"
object above.) I did fine one example where a strongly-typed
ObjectDataSourc e 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="frmvwEmploy eeMain" DataSourceID="o dsEmployeeEdit"
runat="server">
2
3 <ItemTemplate >
4 <table id="tblMainInfo ">
5 <tr>
6 <td class="TabArea" valign="top" style="text-align:
left">
7 <uc2:EmployeeOr g ID="EmployeeOrg 1"
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:resourceke y="lblTitleEnRe source1"
Text="Title (English):"></asp:Label></td>
15 <td colspan="3">
16 <asp:TextBox
ID="txtTitleEn " runat="server" meta:resourceke y="txtTitleEnRe source1"
Text='<%# Bind("TitleEngl ish") %>'></asp:TextBox></td>
17 </tr>
18 <tr>
19 <td style="height: 26px;
width: 114px;">
20 <asp:Label
ID="lblTitleFr " runat="server" meta:resourceke y="lblTitleFrRe source1"
Text="Title (French):"></asp:Label></td>
21 <td colspan="3">
22 <asp:TextBox
ID="txtTitleFr " runat="server" meta:resourceke y="txtTitleFrRe source1"
Text='<%# Bind("TitleFren ch") %>'></asp:TextBox></td>
23 </trSo 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 DirectoryServic esAdapter
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 IDirectoryEntit y) 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(em pl, IDirectoryEntit y))
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_EmployeeUpd ate' 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.Sql Client.SqlExcep tion: Procedure
'sp_EmployeeUpd ate' expects parameter '@surname', which was not supplied.
Source Error:
Line 31: Protected Sub btnUpdate_Click (ByVal sender As Object, ByVal e
As System.EventArg s) Handles btnUpdate.Click
Line 32:
Line 33: _dso.Update()
Line 34:
Line 35: End Sub
Source File: c:\inetpub\wwwr oot\Update500\U serControls\Emp loyeeCRUD.ascx. vb
Line: 33
Stack Trace:
[SqlException (0x80131904): Procedure 'sp_EmployeeUpd ate' expects parameter
'@surname', which was not supplied.]
System.Data.Sql Client.SqlConne ction.OnError(S qlException exception,
Boolean breakConnection ) +857338
System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion
exception, Boolean breakConnection ) +734950
System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct
stateObj) +188
System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet
bulkCopyHandler , TdsParserStateO bject stateObj) +1838
System.Data.Sql Client.SqlComma nd.FinishExecut eReader(SqlData Reader ds,
RunBehavior runBehavior, String resetOptionsStr ing) +149
System.Data.Sql Client.SqlComma nd.RunExecuteRe aderTds(Command Behavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
+886
System.Data.Sql Client.SqlComma nd.RunExecuteRe ader(CommandBeh avior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
DbAsyncResult result) +132
System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult
result, String methodName, Boolean sendToPipe) +415
System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +135
GC.Finance.Web5 00.Data.PSEmplo yee.Update() in C:\Documents and
Settings\rholde r\My Documents\Visua l Studio
2005\Projects\G C.Finance.X500. Data\GC.Finance .X500.Data\Enti ties\PSEmployee .vb:211
GC.Finance.Web5 00.Data.Employe eAdapter.Update (IDirectoryEnti ty de) in
C:\Documents and Settings\rholde r\My Documents\Visua l Studio
2005\Projects\G C.Finance.X500. Data\GC.Finance .X500.Data\Adap ters\EmployeeAd apter.vb:80
GC.Finance.Web5 00.Data.Employe eAdapter.Update (PSEmployee empl) in
C:\Documents and Settings\rholde r\My Documents\Visua l Studio
2005\Projects\G C.Finance.X500. Data\GC.Finance .X500.Data\Adap ters\EmployeeAd apter.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."