Home All Groups Group Topic Archive Search About

ASP.NET 2.0 ObjectDataSource UpdateMethod not passing new values

Author
20 Jan 2006 10:26 PM
anonymike
Hello,

I started working with the ObjectDataSource today.  I have the select,
and have been working on getting the update method to work.  Here is
the asp code for my Data source:

<asp:ObjectDataSource ID="dsourceApps" runat="server"
SelectMethod="getAllApplications"
        TypeName="AppMgr.AppManager" UpdateMethod="updateAppHdr"
        ConflictDetection="CompareAllValues"
OldValuesParameterFormatString="{0}_old"
        OnObjectCreating="dsourceApps_OnObjectCreating"
OnObjectDisposing="dsourceApps_OnObjectDisposing">
        <UpdateParameters>
            <asp:Parameter Name="appid" Type="String" />
            <asp:Parameter Name="appname" Type="String" />
            <asp:Parameter Name="apploc" Type="String" />
            <asp:Parameter Name="appdesc" Type="String" />
            <asp:Parameter Name="appid_old" Type="String" />
            <asp:Parameter Name="appname_old" Type="String" />
            <asp:Parameter Name="apploc_old" Type="String" />
            <asp:Parameter Name="appdesc_old" Type="String" />
        </UpdateParameters>
    </asp:ObjectDataSource>


The function sig for the updateAppHdr function is:

public void updateAppHdr(string appid, string appname, string apploc,
string appdesc, string appid_old, string appname_old, string
apploc_old, string appdesc_old)

The error that I get after I hit the save button after editing a field
in my GridView is:

Exception Details: System.Data.OracleClient.OracleException: ORA-06550:
line 1, column 7:
PLS-00306: wrong number or types of arguments in call to
'ND_UPD_DEFINED_APP'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored


I did some digging, and I'm noticing that all the new values (the
fields without "_old" appended) are coming into the function as NULL.
The old values are coming in properly, but the new values are just
null...

Any ideas why this is happening?  It's actually getting into the
function, so I'm guessing it has something to do with the way the
gridview is setup... I can't seem to find anything on this on google,
or maybe I'm just not sure what to look for...

Thanks in advance for any help,
Mike

Author
20 Jan 2006 11:13 PM
Phillip Williams
In the UpdateAppHdr function can you try setting the values to defaults (if
they were null) before passing them to Oracle and see if that eliminates the
ORA exception?

Show quote
"anonym***@gmail.com" wrote:

> Hello,
>
> I started working with the ObjectDataSource today.  I have the select,
> and have been working on getting the update method to work.  Here is
> the asp code for my Data source:
>
> <asp:ObjectDataSource ID="dsourceApps" runat="server"
> SelectMethod="getAllApplications"
>         TypeName="AppMgr.AppManager" UpdateMethod="updateAppHdr"
>         ConflictDetection="CompareAllValues"
> OldValuesParameterFormatString="{0}_old"
>         OnObjectCreating="dsourceApps_OnObjectCreating"
> OnObjectDisposing="dsourceApps_OnObjectDisposing">
>         <UpdateParameters>
>             <asp:Parameter Name="appid" Type="String" />
>             <asp:Parameter Name="appname" Type="String" />
>             <asp:Parameter Name="apploc" Type="String" />
>             <asp:Parameter Name="appdesc" Type="String" />
>             <asp:Parameter Name="appid_old" Type="String" />
>             <asp:Parameter Name="appname_old" Type="String" />
>             <asp:Parameter Name="apploc_old" Type="String" />
>             <asp:Parameter Name="appdesc_old" Type="String" />
>         </UpdateParameters>
>     </asp:ObjectDataSource>
>
>
> The function sig for the updateAppHdr function is:
>
> public void updateAppHdr(string appid, string appname, string apploc,
> string appdesc, string appid_old, string appname_old, string
> apploc_old, string appdesc_old)
>
> The error that I get after I hit the save button after editing a field
> in my GridView is:
>
> Exception Details: System.Data.OracleClient.OracleException: ORA-06550:
> line 1, column 7:
> PLS-00306: wrong number or types of arguments in call to
> 'ND_UPD_DEFINED_APP'
> ORA-06550: line 1, column 7:
> PL/SQL: Statement ignored
>
>
> I did some digging, and I'm noticing that all the new values (the
> fields without "_old" appended) are coming into the function as NULL.
> The old values are coming in properly, but the new values are just
> null...
>
> Any ideas why this is happening?  It's actually getting into the
> function, so I'm guessing it has something to do with the way the
> gridview is setup... I can't seem to find anything on this on google,
> or maybe I'm just not sure what to look for...
>
> Thanks in advance for any help,
> Mike
>
>
Author
25 Jan 2006 5:08 PM
Mike
Thanks Phillip, I was away for a few days or I would have replied
sooner.

I did what you suggested, in the function to do the update, I went
ahead and hardcoded some values for the "new" fields (bypassing the
NULL's that were coming in) and the stored proc fired and executed just
fine.

The problem has to be with the null's getting passed in, but I can't
seem to track it down yet.  Any more suggestions?

Thanks,
Mike
Author
25 Jan 2006 8:24 PM
Phillip Williams
Welcome back Mike. 

My first guess would be the 2-way databinding.  The ObjectDataSource would
pass null for the parameter values if the databound server control was not
using 2-way databinding, e.g. if you had used itemtemplates in the GridView
with controls bound using the Eval method instead of the Bind, e.g.:
<asp:TextBox ID="txtapploc" runat="server" Text='<%# Eval("apploc"")
%>'></asp:TextBox>

Show quote
"Mike" wrote:

> Thanks Phillip, I was away for a few days or I would have replied
> sooner.
>
> I did what you suggested, in the function to do the update, I went
> ahead and hardcoded some values for the "new" fields (bypassing the
> NULL's that were coming in) and the stored proc fired and executed just
> fine.
>
> The problem has to be with the null's getting passed in, but I can't
> seem to track it down yet.  Any more suggestions?
>
> Thanks,
> Mike
>
>
Author
25 Jan 2006 10:57 PM
Mike
Hi again Phillip...

I did some googling, but I'm not understanding what you mean by this...
how do I implement 2 way databinding between the gridview and my
object?  By using itemtemplates?

I'll keep looking, and thanks again for your help,
Mike


Phillip Williams wrote:
Show quote
> Welcome back Mike.
>
> My first guess would be the 2-way databinding.  The ObjectDataSource would
> pass null for the parameter values if the databound server control was not
> using 2-way databinding, e.g. if you had used itemtemplates in the GridView
> with controls bound using the Eval method instead of the Bind, e.g.:
> <asp:TextBox ID="txtapploc" runat="server" Text='<%# Eval("apploc"")
> %>'></asp:TextBox>
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Mike" wrote:
>
> > Thanks Phillip, I was away for a few days or I would have replied
> > sooner.
> >
> > I did what you suggested, in the function to do the update, I went
> > ahead and hardcoded some values for the "new" fields (bypassing the
> > NULL's that were coming in) and the stored proc fired and executed just
> > fine.
> >
> > The problem has to be with the null's getting passed in, but I can't
> > seem to track it down yet.  Any more suggestions?
> >
> > Thanks,
> > Mike
> >
> >
Author
25 Jan 2006 11:37 PM
Phillip Williams
The 2-way databinding happens when the GridView automatic update is enabled:
“The automatic updating, deleting, and selection functionalities are enabled
when a button in a ButtonField or TemplateField column field, with a command
name of "Edit", "Delete", and "Select", respectively, is clicked. The
GridView control can automatically add a CommandField column field with an
Edit, Delete, or Select button if the AutoGenerateEditButton,
AutoGenerateDeleteButton, or AutoGenerateSelectButton property is set to
true, respectively.”
http://msdn2.microsoft.com/en-us/library/4w7ya1ts.aspx

In editing columns in a GridView one might use a BoundField or a customized
EditItemTemplate combination.  If you use the BoundField and want to enable
the 2-way databinding make sure that the ReadOnly property is not set to true
(the default value is false).  If you used a customized EditItemTemplate
(like I did in this demo
http://www.webswapp.com/CodeSamples/aspnet20/GridView_2c.aspx) then make sure
that you used Bind not Eval to set the values of the TextBoxes.

If this information does not help you solve the problem, you may want to
post the markup for the GridView so that I can take a second look on it for
you.

Show quote
"Mike" wrote:

> Hi again Phillip...
>
> I did some googling, but I'm not understanding what you mean by this...
> how do I implement 2 way databinding between the gridview and my
> object?  By using itemtemplates?
>
> I'll keep looking, and thanks again for your help,
> Mike
>
>
> Phillip Williams wrote:
> > Welcome back Mike.
> >
> > My first guess would be the 2-way databinding.  The ObjectDataSource would
> > pass null for the parameter values if the databound server control was not
> > using 2-way databinding, e.g. if you had used itemtemplates in the GridView
> > with controls bound using the Eval method instead of the Bind, e.g.:
> > <asp:TextBox ID="txtapploc" runat="server" Text='<%# Eval("apploc"")
> > %>'></asp:TextBox>
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "Mike" wrote:
> >
> > > Thanks Phillip, I was away for a few days or I would have replied
> > > sooner.
> > >
> > > I did what you suggested, in the function to do the update, I went
> > > ahead and hardcoded some values for the "new" fields (bypassing the
> > > NULL's that were coming in) and the stored proc fired and executed just
> > > fine.
> > >
> > > The problem has to be with the null's getting passed in, but I can't
> > > seem to track it down yet.  Any more suggestions?
> > >
> > > Thanks,
> > > Mike
> > >
> > >
>
>
Author
26 Jan 2006 4:08 AM
Mike
I checked out your source, and cannot see anything that you're really
doing different than me.  I even changed an item to be a template
column and that did nothing for me as well...

Below is my markup for the gridview and datasource... Thanks again!

--------------------------------------------------
    <asp:GridView ID="gvAppList" runat="server" AllowPaging="True"
AllowSorting="True"
        Caption="Application List" CssClass="tabledisplay"
DataSourceID="dsourceApps"
        HorizontalAlign="Center" PageSize="5" Width="95%"
CaptionAlign="Top" CellPadding="4" ForeColor="#333333"
        GridLines="None" AutoGenerateColumns="False"
OnRowUpdating="gvAppList_OnRowUpdating"
        AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
        AutoGenerateSelectButton="True">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="APPID" HeaderText="App ID"
SortExpression="appid" ApplyFormatInEditMode="True" />
            <asp:TemplateField HeaderText="Name"
SortExpression="APPNAME">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("APPNAME") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%#
Bind("APPNAME") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="APPLOC" HeaderText="Location"
SortExpression="APPLOC"  />
            <asp:BoundField DataField="APPDESC"
HeaderText="Description" SortExpression="APPDESC" />
        </Columns>
        <FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
        <RowStyle BackColor="#EFF3FB" />
        <EditRowStyle BackColor="#2461BF" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
        <PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <asp:ObjectDataSource ID="dsourceApps" runat="server"
SelectMethod="getAllApplications"
        TypeName="AppMgr.AppManager" UpdateMethod="updateAppHdr"
        ConflictDetection="CompareAllValues"
OldValuesParameterFormatString="{0}_old"
        OnObjectCreating="dsourceApps_OnObjectCreating"
OnObjectDisposing="dsourceApps_OnObjectDisposing">
        <UpdateParameters>
            <asp:Parameter Name="appid" Type="String" />
            <asp:Parameter Name="appname" Type="String" />
            <asp:Parameter Name="apploc" Type="String" />
            <asp:Parameter Name="appdesc" Type="String" />
            <asp:Parameter Name="appid_old" Type="String" />
            <asp:Parameter Name="appname_old" Type="String" />
            <asp:Parameter Name="apploc_old" Type="String" />
            <asp:Parameter Name="appdesc_old" Type="String" />
        </UpdateParameters>
    </asp:ObjectDataSource>
---------------------------------------
Author
26 Jan 2006 7:05 AM
Phillip Williams
Hi Mike,

Using the code that you posted, I can only reproduce the situation that you
get if I turn the EnableViewState to false.

Here is your code working as expected:
http://www.webswapp.com/CodeSamples/aspnet20/EnableViewState_true.aspx

Here is your code working as you described:
http://www.webswapp.com/CodeSamples/aspnet20/EnableViewState_false.aspx
Show quote
"Mike" wrote:

> I checked out your source, and cannot see anything that you're really
> doing different than me.  I even changed an item to be a template
> column and that did nothing for me as well...
>
> Below is my markup for the gridview and datasource... Thanks again!
>
> --------------------------------------------------
>     <asp:GridView ID="gvAppList" runat="server" AllowPaging="True"
> AllowSorting="True"
>         Caption="Application List" CssClass="tabledisplay"
> DataSourceID="dsourceApps"
>         HorizontalAlign="Center" PageSize="5" Width="95%"
> CaptionAlign="Top" CellPadding="4" ForeColor="#333333"
>         GridLines="None" AutoGenerateColumns="False"
> OnRowUpdating="gvAppList_OnRowUpdating"
>         AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
>         AutoGenerateSelectButton="True">
>         <Columns>
>             <asp:CommandField ShowSelectButton="True" />
>             <asp:BoundField DataField="APPID" HeaderText="App ID"
> SortExpression="appid" ApplyFormatInEditMode="True" />
>             <asp:TemplateField HeaderText="Name"
> SortExpression="APPNAME">
>                 <EditItemTemplate>
>                     <asp:TextBox ID="TextBox1" runat="server" Text='<%#
> Bind("APPNAME") %>'></asp:TextBox>
>                 </EditItemTemplate>
>                 <ItemTemplate>
>                     <asp:Label ID="Label1" runat="server" Text='<%#
> Bind("APPNAME") %>'></asp:Label>
>                 </ItemTemplate>
>             </asp:TemplateField>
>             <asp:BoundField DataField="APPLOC" HeaderText="Location"
> SortExpression="APPLOC"  />
>             <asp:BoundField DataField="APPDESC"
> HeaderText="Description" SortExpression="APPDESC" />
>         </Columns>
>         <FooterStyle BackColor="#507CD1" Font-Bold="True"
> ForeColor="White" />
>         <RowStyle BackColor="#EFF3FB" />
>         <EditRowStyle BackColor="#2461BF" />
>         <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
> ForeColor="#333333" />
>         <PagerStyle BackColor="#2461BF" ForeColor="White"
> HorizontalAlign="Center" />
>         <HeaderStyle BackColor="#507CD1" Font-Bold="True"
> ForeColor="White" />
>         <AlternatingRowStyle BackColor="White" />
>     </asp:GridView>
>     <asp:ObjectDataSource ID="dsourceApps" runat="server"
> SelectMethod="getAllApplications"
>         TypeName="AppMgr.AppManager" UpdateMethod="updateAppHdr"
>         ConflictDetection="CompareAllValues"
> OldValuesParameterFormatString="{0}_old"
>         OnObjectCreating="dsourceApps_OnObjectCreating"
> OnObjectDisposing="dsourceApps_OnObjectDisposing">
>         <UpdateParameters>
>             <asp:Parameter Name="appid" Type="String" />
>             <asp:Parameter Name="appname" Type="String" />
>             <asp:Parameter Name="apploc" Type="String" />
>             <asp:Parameter Name="appdesc" Type="String" />
>             <asp:Parameter Name="appid_old" Type="String" />
>             <asp:Parameter Name="appname_old" Type="String" />
>             <asp:Parameter Name="apploc_old" Type="String" />
>             <asp:Parameter Name="appdesc_old" Type="String" />
>         </UpdateParameters>
>     </asp:ObjectDataSource>
> ---------------------------------------
>
>
Author
26 Jan 2006 3:53 PM
Mike
Phillip,

I went back and explicitely set the EnableViewState="true" on the page,
masterpage, and gridview control, but still no go.  I can see that it
works for you, but for some reason still no go here... I can see in the
page source when it's rendered in a browser that I am getting the
viewstate in the browser, I thought maybe it's getting "lost" somewhere
in the three page loads that happen, but I can't seem to view the
ViewState variable running in Debug mode (I'm not adding anything to it
through the code, so I probably just can't see what .NET adds to it
internally)...

I guess I'll try to do it without the Masterpage and see if I can't get
it to work...

I'll post back in a bit..
Author
26 Jan 2006 3:59 PM
Mike
I took the code out of the masterpage and put it in it's own page,
hooked up the necessary events and fired it off and the values are
coming through fine, just like on your site.

So I guess now the question moves on to why is the masterpage messing
with my viewstate values on the return?

Thanks again for your help,
Mike
Author
26 Jan 2006 6:12 PM
Phillip Williams
Hello Mike,

Placing the code within the masterpage (in itself) should not be the cause
of the problem.  Here is the same demo with the code moved to the master page
and it is still working:
http://www.webswapp.com/CodeSamples/aspnet20/EnableViewState_true2.aspx

The page's EnableViewState setting should override the web.config file
setting, so even if your web.config filehad a line like this:
<pages EnableViewState="false">

your master page should have still worked if your page specifically had the
enableViewState=”true”

Show quote
"Mike" wrote:

> I took the code out of the masterpage and put it in it's own page,
> hooked up the necessary events and fired it off and the values are
> coming through fine, just like on your site.
>
> So I guess now the question moves on to why is the masterpage messing
> with my viewstate values on the return?
>
> Thanks again for your help,
> Mike
>
>
Author
26 Jan 2006 8:04 PM
Mike
I should have explained that better... the datagrid is on a content
page, using a masterpage, not on the masterpage itself.  Of course, I
cannot see why this would be the problem, but when I copy the code out
of the content page onto a regular page (not using a masterpage)
verbatim, it works.

Is there a way for me to view the viewstate (what's being sent back
from the browser) while in debug mode?  Maybe I can watch it through
execution after clicking update and see where it might be getting
cleared.
Author
26 Jan 2006 8:18 PM
Mike
Phillip,

I found the cause.  There's a user control in my master page that holds
a username/password (login-type) area.  This is all that is going into
the viewstate (found it in the trace output), so when I'm clicking the
update button on the grid, it's not sending those updated values back
(the viewstate only contains the username & password fields).

I removed the username/pw form and tried again, and sure enough, the
values got passed properly.

Off to figure out why ... Thanks again very much for all the help, I
greatly appreciate it.

Mike
Author
26 Jan 2006 9:06 PM
Phillip Williams
You are very welcome.
Show quote
"Mike" wrote:

> Phillip,
>
> I found the cause.  There's a user control in my master page that holds
> a username/password (login-type) area.  This is all that is going into
> the viewstate (found it in the trace output), so when I'm clicking the
> update button on the grid, it's not sending those updated values back
> (the viewstate only contains the username & password fields).
>
> I removed the username/pw form and tried again, and sure enough, the
> values got passed properly.
>
> Off to figure out why ... Thanks again very much for all the help, I
> greatly appreciate it.
>
> Mike
>
>

AddThis Social Bookmark Button