Home All Groups Group Topic Archive Search About

formview with objectDataSource won't display data

Author
10 Mar 2006 3:21 PM
John Hopper
I have a formview configured to use an objectDataSource. The select method
name matches a function name in my class, and the class name matches the
typeName of the objectData Source. My function returns a dataReader. The
dataObjectTypeName matches the dataSource name of the formView. I get no
runtime errors, but there is not data displayed in the formView when the
project is run. Any ideas appreciated.

<asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
SelectMethod="getDetails" DataObjectTypeName="formSource">
            <SelectParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <div>
            <asp:FormView ID="FormView1" runat="server"  BorderWidth=1px
                Caption="Details" CaptionAlign="Left"
DataSourceID="formSource" Width="40%" DataKeyNames="ID">
                <ItemTemplate>
                    <div>
                        <asp:Button ID="btnEdit" runat=server
CommandName="Edit" />
                    </div>
                </ItemTemplate>
                <EditItemTemplate>

---------------------


Public Class myDataLayer

    Public Function getDetails(ByVal ID As Integer) As
System.Data.SqlClient.SqlDataReader

        Dim queryString As String = "select description from tblProjects
where ID = ID"
        Dim connectionString As String = "Data Source=Magellan;Initial
Catalog=SS;User ID=ssUser2;Password="

        Dim connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand(queryString, connection)
        connection.Open()
        Dim reader As SqlDataReader = command.ExecuteReader
        While reader.Read

        End While
        Return reader

    End Function



End Class

Author
10 Mar 2006 4:57 PM
Phillip Williams
Good Morning John,

The difficulty in the code you wrote is the usage of the SqlDataReader with
the ObjectDataSource.   I am surprised you did not get a runtime error While
the SqlDataSource object would allow you to set the DataSourceMode to
DataReader, the ObjectDataSource on the other hand, as the stated in the
documentation does not.  Here is a quotation from the MSDN:

"The ObjectDataSource control can filter data that is retrieved by the
SelectMethod property, if the data is returned as a DataSet, DataView, or
DataTable object. The ObjectDataSource control allows you to cache all types
of data, but you should not cache objects that retain resources or state that
cannot be shared to service multiple requests (for example, an open
SqlDataReader object), because this same instance of the object will be used
to service multiple requests. " http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx

Modify your function to use a SqlDataAdapater and return a DataSet instead.
---
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Show quoteHide quote
"John Hopper" wrote:

> I have a formview configured to use an objectDataSource. The select method
> name matches a function name in my class, and the class name matches the
> typeName of the objectData Source. My function returns a dataReader. The
> dataObjectTypeName matches the dataSource name of the formView. I get no
> runtime errors, but there is not data displayed in the formView when the
> project is run. Any ideas appreciated.
>
> <asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
> SelectMethod="getDetails" DataObjectTypeName="formSource">
>             <SelectParameters>
>                 <asp:Parameter Name="ID" Type="Int32" />
>             </SelectParameters>
>         </asp:ObjectDataSource>
>         <div>
>             <asp:FormView ID="FormView1" runat="server"  BorderWidth=1px
>                 Caption="Details" CaptionAlign="Left"
> DataSourceID="formSource" Width="40%" DataKeyNames="ID">
>                 <ItemTemplate>
>                     <div>
>                         <asp:Button ID="btnEdit" runat=server
> CommandName="Edit" />
>                     </div>
>                 </ItemTemplate>
>                 <EditItemTemplate>
>
> ---------------------
>
>
> Public Class myDataLayer
>
>     Public Function getDetails(ByVal ID As Integer) As
> System.Data.SqlClient.SqlDataReader
>
>         Dim queryString As String = "select description from tblProjects
> where ID = ID"
>         Dim connectionString As String = "Data Source=Magellan;Initial
> Catalog=SS;User ID=ssUser2;Password="
>
>         Dim connection As New SqlConnection(connectionString)
>         Dim command As New SqlCommand(queryString, connection)
>         connection.Open()
>         Dim reader As SqlDataReader = command.ExecuteReader
>         While reader.Read
>
>         End While
>         Return reader
>
>     End Function
>
>
>
> End Class
>
Author
10 Mar 2006 5:18 PM
Phillip Williams
On second thought, and after trying it myself, it works, but only if disable
the paging on the FormView.  If the DataReader were to return more than one
record and FormView paging is enabled, one would get an error message that
"The datasource does not support server-side data paging".

Ok, so the problem in your code was simply that you executed "While
reader.Read...End While" loop before you returned the reader.  Comment out
those 2 lines of code and you should have it working fine.
Show quoteHide quote
"Phillip Williams" wrote:

> Good Morning John,
>
> The difficulty in the code you wrote is the usage of the SqlDataReader with
> the ObjectDataSource.   I am surprised you did not get a runtime error While
> the SqlDataSource object would allow you to set the DataSourceMode to
> DataReader, the ObjectDataSource on the other hand, as the stated in the
> documentation does not.  Here is a quotation from the MSDN:
>
> "The ObjectDataSource control can filter data that is retrieved by the
> SelectMethod property, if the data is returned as a DataSet, DataView, or
> DataTable object. The ObjectDataSource control allows you to cache all types
> of data, but you should not cache objects that retain resources or state that
> cannot be shared to service multiple requests (for example, an open
> SqlDataReader object), because this same instance of the object will be used
> to service multiple requests. "
> http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx
>
> Modify your function to use a SqlDataAdapater and return a DataSet instead.
> ---
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "John Hopper" wrote:
>
> > I have a formview configured to use an objectDataSource. The select method
> > name matches a function name in my class, and the class name matches the
> > typeName of the objectData Source. My function returns a dataReader. The
> > dataObjectTypeName matches the dataSource name of the formView. I get no
> > runtime errors, but there is not data displayed in the formView when the
> > project is run. Any ideas appreciated.
> >
> > <asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
> > SelectMethod="getDetails" DataObjectTypeName="formSource">
> >             <SelectParameters>
> >                 <asp:Parameter Name="ID" Type="Int32" />
> >             </SelectParameters>
> >         </asp:ObjectDataSource>
> >         <div>
> >             <asp:FormView ID="FormView1" runat="server"  BorderWidth=1px
> >                 Caption="Details" CaptionAlign="Left"
> > DataSourceID="formSource" Width="40%" DataKeyNames="ID">
> >                 <ItemTemplate>
> >                     <div>
> >                         <asp:Button ID="btnEdit" runat=server
> > CommandName="Edit" />
> >                     </div>
> >                 </ItemTemplate>
> >                 <EditItemTemplate>
> >
> > ---------------------
> >
> >
> > Public Class myDataLayer
> >
> >     Public Function getDetails(ByVal ID As Integer) As
> > System.Data.SqlClient.SqlDataReader
> >
> >         Dim queryString As String = "select description from tblProjects
> > where ID = ID"
> >         Dim connectionString As String = "Data Source=Magellan;Initial
> > Catalog=SS;User ID=ssUser2;Password="
> >
> >         Dim connection As New SqlConnection(connectionString)
> >         Dim command As New SqlCommand(queryString, connection)
> >         connection.Open()
> >         Dim reader As SqlDataReader = command.ExecuteReader
> >         While reader.Read
> >
> >         End While
> >         Return reader
> >
> >     End Function
> >
> >
> >
> > End Class
> >
Author
10 Mar 2006 5:18 PM
John Hopper
I see. Thank you again for your very valuable help.

John Hopper

Show quoteHide quote
"Phillip Williams" wrote:

> Good Morning John,
>
> The difficulty in the code you wrote is the usage of the SqlDataReader with
> the ObjectDataSource.   I am surprised you did not get a runtime error While
> the SqlDataSource object would allow you to set the DataSourceMode to
> DataReader, the ObjectDataSource on the other hand, as the stated in the
> documentation does not.  Here is a quotation from the MSDN:
>
> "The ObjectDataSource control can filter data that is retrieved by the
> SelectMethod property, if the data is returned as a DataSet, DataView, or
> DataTable object. The ObjectDataSource control allows you to cache all types
> of data, but you should not cache objects that retain resources or state that
> cannot be shared to service multiple requests (for example, an open
> SqlDataReader object), because this same instance of the object will be used
> to service multiple requests. "
> http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx
>
> Modify your function to use a SqlDataAdapater and return a DataSet instead.
> ---
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "John Hopper" wrote:
>
> > I have a formview configured to use an objectDataSource. The select method
> > name matches a function name in my class, and the class name matches the
> > typeName of the objectData Source. My function returns a dataReader. The
> > dataObjectTypeName matches the dataSource name of the formView. I get no
> > runtime errors, but there is not data displayed in the formView when the
> > project is run. Any ideas appreciated.
> >
> > <asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
> > SelectMethod="getDetails" DataObjectTypeName="formSource">
> >             <SelectParameters>
> >                 <asp:Parameter Name="ID" Type="Int32" />
> >             </SelectParameters>
> >         </asp:ObjectDataSource>
> >         <div>
> >             <asp:FormView ID="FormView1" runat="server"  BorderWidth=1px
> >                 Caption="Details" CaptionAlign="Left"
> > DataSourceID="formSource" Width="40%" DataKeyNames="ID">
> >                 <ItemTemplate>
> >                     <div>
> >                         <asp:Button ID="btnEdit" runat=server
> > CommandName="Edit" />
> >                     </div>
> >                 </ItemTemplate>
> >                 <EditItemTemplate>
> >
> > ---------------------
> >
> >
> > Public Class myDataLayer
> >
> >     Public Function getDetails(ByVal ID As Integer) As
> > System.Data.SqlClient.SqlDataReader
> >
> >         Dim queryString As String = "select description from tblProjects
> > where ID = ID"
> >         Dim connectionString As String = "Data Source=Magellan;Initial
> > Catalog=SS;User ID=ssUser2;Password="
> >
> >         Dim connection As New SqlConnection(connectionString)
> >         Dim command As New SqlCommand(queryString, connection)
> >         connection.Open()
> >         Dim reader As SqlDataReader = command.ExecuteReader
> >         While reader.Read
> >
> >         End While
> >         Return reader
> >
> >     End Function
> >
> >
> >
> > End Class
> >
Author
10 Mar 2006 5:22 PM
CaffieneRush@gmail.com
First - leave off the DataObjectTypeName.

If specified it will be used by the ODS as the class name of a custom
data transfer used in the Update/Delete/Insert method which in your
case are undeclared in the class myDataLayer.
http://msdn2.microsoft.com/en-us/library/4b97t57y(vs.80).aspx

Second - return a DataSet rather than a DataReader from getDetails()
and see if that fixes things.

Thirdly - if you still want to return a DataReader then think of
DataReader as one way data hose. You cannot go back and read more data
once you've read all the data from the DataReader.
So take out the While .. End While block within getDetails.

Finally - if you are returning a DataReader then it is better to use
SqlDataSource directly.

Good luck.
Author
10 Mar 2006 6:52 PM
John Hopper
Thank you both for your help and suggestions. I only started to use an
objectDataSource because I need to update multiple tables from a formView,
which is a child of a gridView. I only care about displaying the last
update's detail in the formView, although an item in the parent gridView may
have more than one update. That is why I used a datareader, although I
understand I should probably use a dataSet. However using either, I'm having
trouble passing the GridView's selected item's ID to the formView. I would
guess that I need to set the formView's dataSource query's ID to the
GridView's selected item's ID, but I don't see how to do that in design view.

Hope I haven't worn out my welcome on this one yet.

Thanks!

John Hopper

Show quoteHide quote
"John Hopper" wrote:

> I have a formview configured to use an objectDataSource. The select method
> name matches a function name in my class, and the class name matches the
> typeName of the objectData Source. My function returns a dataReader. The
> dataObjectTypeName matches the dataSource name of the formView. I get no
> runtime errors, but there is not data displayed in the formView when the
> project is run. Any ideas appreciated.
>
> <asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
> SelectMethod="getDetails" DataObjectTypeName="formSource">
>             <SelectParameters>
>                 <asp:Parameter Name="ID" Type="Int32" />
>             </SelectParameters>
>         </asp:ObjectDataSource>
>         <div>
>             <asp:FormView ID="FormView1" runat="server"  BorderWidth=1px
>                 Caption="Details" CaptionAlign="Left"
> DataSourceID="formSource" Width="40%" DataKeyNames="ID">
>                 <ItemTemplate>
>                     <div>
>                         <asp:Button ID="btnEdit" runat=server
> CommandName="Edit" />
>                     </div>
>                 </ItemTemplate>
>                 <EditItemTemplate>
>
> ---------------------
>
>
> Public Class myDataLayer
>
>     Public Function getDetails(ByVal ID As Integer) As
> System.Data.SqlClient.SqlDataReader
>
>         Dim queryString As String = "select description from tblProjects
> where ID = ID"
>         Dim connectionString As String = "Data Source=Magellan;Initial
> Catalog=SS;User ID=ssUser2;Password="
>
>         Dim connection As New SqlConnection(connectionString)
>         Dim command As New SqlCommand(queryString, connection)
>         connection.Open()
>         Dim reader As SqlDataReader = command.ExecuteReader
>         While reader.Read
>
>         End While
>         Return reader
>
>     End Function
>
>
>
> End Class
>
Author
10 Mar 2006 7:13 PM
Phillip Williams
Assuming that your GridView has one or several DataKeys; the first of which
is the ID and assuming it is of type Int32 then you can write:

<asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
SelectMethod="getDetails" DataObjectTypeName="formSource">
            <SelectParameters>
                      <asp:ControlParameter Name="ID"  ControlID="GridView1"
PropertyName="SelectedDataKey.Values[0]"
Type="Int32"
            </SelectParameters>
        </asp:ObjectDataSource>

Do not worry about wearing out your welcome :)  You are quite welcome.

You might also look at the source code of this demo to find out the bits of
code that help you get the DataKeys of the GridView.
http://www.webswapp.com/codesamples/aspnet20/nestedgridviews/default.aspx

Show quoteHide quote
"John Hopper" wrote:

> Thank you both for your help and suggestions. I only started to use an
> objectDataSource because I need to update multiple tables from a formView,
> which is a child of a gridView. I only care about displaying the last
> update's detail in the formView, although an item in the parent gridView may
> have more than one update. That is why I used a datareader, although I
> understand I should probably use a dataSet. However using either, I'm having
> trouble passing the GridView's selected item's ID to the formView. I would
> guess that I need to set the formView's dataSource query's ID to the
> GridView's selected item's ID, but I don't see how to do that in design view.
>
> Hope I haven't worn out my welcome on this one yet.
>
> Thanks!
>
> John Hopper
>
> "John Hopper" wrote:
>
> > I have a formview configured to use an objectDataSource. The select method
> > name matches a function name in my class, and the class name matches the
> > typeName of the objectData Source. My function returns a dataReader. The
> > dataObjectTypeName matches the dataSource name of the formView. I get no
> > runtime errors, but there is not data displayed in the formView when the
> > project is run. Any ideas appreciated.
> >
> > <asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
> > SelectMethod="getDetails" DataObjectTypeName="formSource">
> >             <SelectParameters>
> >                 <asp:Parameter Name="ID" Type="Int32" />
> >             </SelectParameters>
> >         </asp:ObjectDataSource>
> >         <div>
> >             <asp:FormView ID="FormView1" runat="server"  BorderWidth=1px
> >                 Caption="Details" CaptionAlign="Left"
> > DataSourceID="formSource" Width="40%" DataKeyNames="ID">
> >                 <ItemTemplate>
> >                     <div>
> >                         <asp:Button ID="btnEdit" runat=server
> > CommandName="Edit" />
> >                     </div>
> >                 </ItemTemplate>
> >                 <EditItemTemplate>
> >
> > ---------------------
> >
> >
> > Public Class myDataLayer
> >
> >     Public Function getDetails(ByVal ID As Integer) As
> > System.Data.SqlClient.SqlDataReader
> >
> >         Dim queryString As String = "select description from tblProjects
> > where ID = ID"
> >         Dim connectionString As String = "Data Source=Magellan;Initial
> > Catalog=SS;User ID=ssUser2;Password="
> >
> >         Dim connection As New SqlConnection(connectionString)
> >         Dim command As New SqlCommand(queryString, connection)
> >         connection.Open()
> >         Dim reader As SqlDataReader = command.ExecuteReader
> >         While reader.Read
> >
> >         End While
> >         Return reader
> >
> >     End Function
> >
> >
> >
> > End Class
> >
Author
10 Mar 2006 7:48 PM
John Hopper
Thank you again for your help! I have copied my gridView and formView source
below because I believe I do have the properties set as you describe, however
I still can't seem to get the selectedItem's ID passed to the ID parameter of
my objectDataSource's query:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:SSConnectionString %>"
            SelectCommand="SELECT     Name, Description, Department,
CurrentStatus, ProjectLead, LastUpdate, ID FROM         dbo.tblProjects
WHERE     (CurrentStatus <> 'Deleted') AND (CurrentStatus <> 'Completed') OR
                      (CurrentStatus <> 'Deleted') AND (CurrentStatus =
'Completed') AND (LastUpdate >= DATEADD(d, - 30, GETDATE()))
ORDER BY LastUpdate DESC" UpdateCommand="Update [tblProjects] set
description = @Description where [ID] = ID">
            <UpdateParameters>
                <asp:Parameter Name="Description" />
                <asp:Parameter Name="ID" />
            </UpdateParameters>
        </asp:SqlDataSource>

        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"
            AutoGenerateColumns="False" DataKeyNames="ID"
            DataSourceID="SqlDataSource1" style="width:50%;float:left"
Font-Size="Small">
            <Columns>
                <asp:ButtonField ButtonType="Button" Text="Select"
CommandName="Select" >
                    <ItemStyle HorizontalAlign="Center" />
                </asp:ButtonField>
                <asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
                <asp:BoundField DataField="ProjectLead" HeaderText="Lead"
SortExpression="ProjectLead" />
                <asp:BoundField DataField="Department"
HeaderText="Department" SortExpression="Department" />
                <asp:BoundField DataField="LastUpdate"
HeaderText="LastUpdate" SortExpression="LastUpdate" />
            </Columns>
            <SelectedRowStyle BackColor="#E0E0E0" />
        </asp:GridView>

        <asp:ObjectDataSource ID="formSource" runat="server"
TypeName="myDataLayer" SelectMethod="getDetails">

            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="ID"
PropertyName="SelectedDataKey.Values[0]" Type=Int32/>
            </SelectParameters>


        </asp:ObjectDataSource>
        <div>
            <asp:FormView ID="FormView1" runat="server"  BorderWidth=1px
                Caption="Details" CaptionAlign="Left"
DataSourceID="formSource" Width="40%" DataKeyNames="ID" >
                <ItemTemplate>
                    <div>
                        <asp:Button ID="btnEdit" runat=server
CommandName="Edit"  Text="Edit"/>
                    </div>
                </ItemTemplate>
                <EditItemTemplate>
                    <div>
                        ID:<asp:Label ID="Label1" runat="server" Text='<%#
Bind("ID") %>'></asp:Label></div>
                    <br />
                    <div>
                        Description:</div>
                    <div>
                        <asp:TextBox ID="txtDescription" runat="server"
Height="100px" Text='<%# Bind("Description") %>'
                            TextMode="multiLine"
Width="100%"></asp:TextBox></div>
                    <br />
                    <div>
                        Status: <asp:DropDownList ID="ddStatus"
runat="server">
                            <asp:ListItem
Value="Completed">Completed</asp:ListItem>
                            <asp:ListItem
Value="Deleted">Deleted</asp:ListItem>
                            <asp:ListItem Value="In Progress">In
Progress</asp:ListItem>
                            <asp:ListItem Value="On Hold">On
Hold</asp:ListItem>
                            <asp:ListItem
Value="Pending">Pending</asp:ListItem>
                        </asp:DropDownList></div>
                    <br />
                    <div>
                        Lead: <asp:DropDownList ID="DropDownList1"
runat="server">
                            <asp:ListItem Value="John Crossman">John
Crossman</asp:ListItem>
                            <asp:ListItem Value="Mark Dutton">Mark
Dutton</asp:ListItem>
                            <asp:ListItem Value="Dana Gentry">Dana
Gentry</asp:ListItem>
                            <asp:ListItem Value="John Hopper">John
Hopper</asp:ListItem>
                            <asp:ListItem Value="Alex Kail">Alex
Kail</asp:ListItem>
                            <asp:ListItem Value="Sowjanya Valluri">Sowjanya
Valluri</asp:ListItem>
                        </asp:DropDownList></div>
                    <br />

                </EditItemTemplate>

            </asp:FormView>
        </div>
    </div>

---------------------------


Public Class myDataLayer

    Public Function getDetails(ByVal ID As Integer) As
System.Data.SqlClient.SqlDataReader

        Dim queryString As String = "select description, ID from tblProjects
where ID = 28"
        Dim connectionString As String = "Data Source=Magellan;Initial
Catalog=SS;User ID=ssUser2;Password="

        Dim connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand(queryString, connection)
        connection.Open()
        Dim reader As SqlDataReader = command.ExecuteReader
        'While reader.Read

        'End While
        Return reader

    End Function



End Class
---------------
Any help appreciated!




Show quoteHide quote
"Phillip Williams" wrote:

> Assuming that your GridView has one or several DataKeys; the first of which
> is the ID and assuming it is of type Int32 then you can write:
>
Author
10 Mar 2006 7:50 PM
John Hopper
Phillip,

Please disregard my last post. Indeed with your suggestions the formView is
now displaying details from the gridView's selected item, as desired. Thanks
very much!

I had my classes' query parameter inside quotes, and so I didn't see that
your suggestions were correct and complete.

Thanks again!


John Hopper

Show quoteHide quote
"Phillip Williams" wrote:

> Assuming that your GridView has one or several DataKeys; the first of which
> is the ID and assuming it is of type Int32 then you can write:
>
> <asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
> SelectMethod="getDetails" DataObjectTypeName="formSource">
>             <SelectParameters>
>                       <asp:ControlParameter Name="ID"  ControlID="GridView1"
> PropertyName="SelectedDataKey.Values[0]"
> Type="Int32"
>             </SelectParameters>
>         </asp:ObjectDataSource>
>
> Do not worry about wearing out your welcome :)  You are quite welcome.
>
> You might also look at the source code of this demo to find out the bits of
> code that help you get the DataKeys of the GridView.
> http://www.webswapp.com/codesamples/aspnet20/nestedgridviews/default.aspx
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "John Hopper" wrote:
>
> > Thank you both for your help and suggestions. I only started to use an
> > objectDataSource because I need to update multiple tables from a formView,
> > which is a child of a gridView. I only care about displaying the last
> > update's detail in the formView, although an item in the parent gridView may
> > have more than one update. That is why I used a datareader, although I
> > understand I should probably use a dataSet. However using either, I'm having
> > trouble passing the GridView's selected item's ID to the formView. I would
> > guess that I need to set the formView's dataSource query's ID to the
> > GridView's selected item's ID, but I don't see how to do that in design view.
> >
> > Hope I haven't worn out my welcome on this one yet.
> >
> > Thanks!
> >
> > John Hopper
> >
> > "John Hopper" wrote:
> >
> > > I have a formview configured to use an objectDataSource. The select method
> > > name matches a function name in my class, and the class name matches the
> > > typeName of the objectData Source. My function returns a dataReader. The
> > > dataObjectTypeName matches the dataSource name of the formView. I get no
> > > runtime errors, but there is not data displayed in the formView when the
> > > project is run. Any ideas appreciated.
> > >
> > > <asp:ObjectDataSource ID="formSource" runat="server" TypeName="myDataLayer"
> > > SelectMethod="getDetails" DataObjectTypeName="formSource">
> > >             <SelectParameters>
> > >                 <asp:Parameter Name="ID" Type="Int32" />
> > >             </SelectParameters>
> > >         </asp:ObjectDataSource>
> > >         <div>
> > >             <asp:FormView ID="FormView1" runat="server"  BorderWidth=1px
> > >                 Caption="Details" CaptionAlign="Left"
> > > DataSourceID="formSource" Width="40%" DataKeyNames="ID">
> > >                 <ItemTemplate>
> > >                     <div>
> > >                         <asp:Button ID="btnEdit" runat=server
> > > CommandName="Edit" />
> > >                     </div>
> > >                 </ItemTemplate>
> > >                 <EditItemTemplate>
> > >
> > > ---------------------
> > >
> > >
> > > Public Class myDataLayer
> > >
> > >     Public Function getDetails(ByVal ID As Integer) As
> > > System.Data.SqlClient.SqlDataReader
> > >
> > >         Dim queryString As String = "select description from tblProjects
> > > where ID = ID"
> > >         Dim connectionString As String = "Data Source=Magellan;Initial
> > > Catalog=SS;User ID=ssUser2;Password="
> > >
> > >         Dim connection As New SqlConnection(connectionString)
> > >         Dim command As New SqlCommand(queryString, connection)
> > >         connection.Open()
> > >         Dim reader As SqlDataReader = command.ExecuteReader
> > >         While reader.Read
> > >
> > >         End While
> > >         Return reader
> > >
> > >     End Function
> > >
> > >
> > >
> > > End Class
> > >