473,715 Members | 5,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview not displaying data - please help!

Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSour ce".
In turn, this ObjectDatasourc e gets it's data from a strongly-typed
business object within my code.
I'm also trying to use custom paging, so my class has correctly
implemented methods to return the total count of records, and also the
method which retrieves the actual page of records is accepting two
parameters for the startRowIndex and maximumRows. I do NOT need any
sorting capability for this gridview, nor do I need any updating,
deleting, selecting functionality, either. I simply need to display
all the relevant records from the database (via my object), paged
(using SQL2005's ROW_NUMBER style paging).

I have this working beautifully when I use a strongly-typed dataset
for the ObjectDatasourc e's data, however, when I switch to using a
"business object", the Gridview doesn't seem to want to display any
data.

I can step through my code, and confirm that I am retrieving some
records from the database, which is then "returned" from the
"selectmeth od" function call as a Generic List (ie. List(of T)).

Below, I've pasted some code that highlights my problem (I re-did the
code to focus on this one problem - in my real code, my DAL and BLL
are separate, whereas here they're in the same class, just for
brevity's sake). If your interested, you can download the entire
zipped up webproject (about 580kb) from here:
http://putstuff.putfile.com/17957/6448935
Has anyone encountered this problem before?? Does anyone know what
I'm doing wrong?? (I'm convinved it's something really simple that
I'm missing).

Any/all replies are greatly appreciated.
Regards,
Greg

The database has one table, as follows:

CREATE TABLE [dbo].[TestTable] (
[UniqueID] [uniqueidentifie r] NOT NULL ,
[Name] [varchar] (50) NOT NULL ,
[BirthDate] [datetime] NOT NULL ,
[Comment] [varchar] (100) NOT NULL
)


There's 2 stored procedures, as follows:

ALTER PROCEDURE dbo.usp_GetTest Table
(
@startRowIndex int,
@maximumRows int
)

AS

SELECT UniqueID, [Name], BirthDate, Comment
FROM

(SELECT UniqueID, [Name], BirthDate, Comment, ROW_NUMBER()
OVER(ORDER BY BirthDate) AS RowNum
FROM TestTable
) AS TestTableList
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex +
@maximumRows) - 1
and:

ALTER PROCEDURE dbo.usp_GetTest TableCount

AS

SELECT
COUNT(*)
FROM
TestTable


The "custom class" is defined as follows:

Imports Microsoft.Visua lBasic
Imports System.Collecti ons.Generic
Imports system.data
Imports System.Data.Sql
Imports system.Data.Sql Client

'
'
'
Public Class TestTableClass
'
'
Private m_UniqueID As String = ""
Private m_Name As String = ""
Private m_BirthDate As DateTime = Nothing
Private m_Comment As String = ""
'
'
Public Property UniqueID() As String
Get
Return m_UniqueID
End Get
Set(ByVal value As String)
m_UniqueID = value
End Set
End Property
'
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property
'
Public Property BirthDate() As DateTime
Get
Return m_BirthDate
End Get
Set(ByVal value As DateTime)
m_BirthDate = value
End Set
End Property
'
Public Property Comment() As String
Get
Return m_Comment
End Get
Set(ByVal value As String)
m_Comment = value
End Set
End Property
'
'
'
Public Function GetTestTableCou nt() As Integer
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(C onfigurationMan ager.Connection Strings("SiteDB ").ToString )
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connect ion = oSQLConn
oSQLCmd.Command Type = CommandType.Sto redProcedure
oSQLCmd.Command Text = "usp_GetTestTab leCount"
'
intResult = oSQLCmd.Execute Scalar
'
oSQLConn.Close( )
'
End Function
'
'
Public Function GetTestTable(By Val startRowIndex As Integer, ByVal
maximumRows As Integer) As List(Of TestTableClass)
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim oSQLParam As SqlParameter
Dim oDR As SqlDataReader
Dim mTTC As TestTableClass
Dim mColl As List(Of TestTableClass) = New List(Of
TestTableClass)
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(C onfigurationMan ager.Connection Strings("SiteDB ").ToString )
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connect ion = oSQLConn
oSQLCmd.Command Type = CommandType.Sto redProcedure
oSQLCmd.Command Text = "usp_GetTestTab le"
'
oSQLParam = New SqlParameter
oSQLParam.SqlDb Type = SqlDbType.Int
oSQLParam.Direc tion = ParameterDirect ion.Input
oSQLParam.Param eterName = "startRowIn dex"
oSQLParam.Value = startRowIndex
oSQLCmd.Paramet ers.Add(oSQLPar am)
'
oSQLParam = New SqlParameter
oSQLParam.SqlDb Type = SqlDbType.Int
oSQLParam.Direc tion = ParameterDirect ion.Input
oSQLParam.Param eterName = "maximumRow s"
oSQLParam.Value = maximumRows
oSQLCmd.Paramet ers.Add(oSQLPar am)
'
oDR = oSQLCmd.Execute Reader()
'
While oDR.Read
'
mTTC = New TestTableClass
mTTC.UniqueID = oDR.Item("Uniqu eID").ToString
mTTC.Name = oDR.Item("Name" ).ToString
mTTC.BirthDate = oDR.Item("Birth Date")
mTTC.Comment = oDR.Item("Comme nt").ToString
'
mColl.Add(mTTC)
'
End While
'
oSQLConn.Close( )
'
Return mColl
'
End Function
'
'
End Class

And the "Default.as px" page (which has nothing in it's code-behind) is
defined as follows:

<%@ Page Language="VB" AutoEventWireup ="false"
CodeFile="Defau lt.aspx.vb" Inherits="_Defa ult" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
TypeName="TestT ableClass" SelectCountMeth od="GetTestTabl eCount"
SelectMethod="G etTestTable" EnablePaging="T rue">
</asp:ObjectDataS ource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
AutoGenerateCol umns="False"
DataSourceID="O bjectDataSource 1">
<Columns>
<asp:BoundFie ld DataField="Uniq ueID"
HeaderText="Uni queID" SortExpression= "UniqueID" />
<asp:BoundFie ld DataField="Birt hDate"
HeaderText="Bir thDate" SortExpression= "BirthDate" />
<asp:BoundFie ld DataField="Name " HeaderText="Nam e"
SortExpression= "Name" />
<asp:BoundFie ld DataField="Comm ent"
HeaderText="Com ment" SortExpression= "Comment" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

Nov 29 '06 #1
8 18081
Why not try:

1. Turn off the paging.

2. Change the type of data structure being returned, instead of List< >.
Start with a simple DataTable being returned.

And see if these produce different outcomes.

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:md******** *************** *********@4ax.c om...
Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSour ce".
In turn, this ObjectDatasourc e gets it's data from a strongly-typed
business object within my code.
I'm also trying to use custom paging, so my class has correctly
implemented methods to return the total count of records, and also the
method which retrieves the actual page of records is accepting two
parameters for the startRowIndex and maximumRows. I do NOT need any
sorting capability for this gridview, nor do I need any updating,
deleting, selecting functionality, either. I simply need to display
all the relevant records from the database (via my object), paged
(using SQL2005's ROW_NUMBER style paging).

I have this working beautifully when I use a strongly-typed dataset
for the ObjectDatasourc e's data, however, when I switch to using a
"business object", the Gridview doesn't seem to want to display any
data.

I can step through my code, and confirm that I am retrieving some
records from the database, which is then "returned" from the
"selectmeth od" function call as a Generic List (ie. List(of T)).

Below, I've pasted some code that highlights my problem (I re-did the
code to focus on this one problem - in my real code, my DAL and BLL
are separate, whereas here they're in the same class, just for
brevity's sake). If your interested, you can download the entire
zipped up webproject (about 580kb) from here:
http://putstuff.putfile.com/17957/6448935
Has anyone encountered this problem before?? Does anyone know what
I'm doing wrong?? (I'm convinved it's something really simple that
I'm missing).

Any/all replies are greatly appreciated.
Regards,
Greg

The database has one table, as follows:

CREATE TABLE [dbo].[TestTable] (
[UniqueID] [uniqueidentifie r] NOT NULL ,
[Name] [varchar] (50) NOT NULL ,
[BirthDate] [datetime] NOT NULL ,
[Comment] [varchar] (100) NOT NULL
)


There's 2 stored procedures, as follows:

ALTER PROCEDURE dbo.usp_GetTest Table
(
@startRowIndex int,
@maximumRows int
)

AS

SELECT UniqueID, [Name], BirthDate, Comment
FROM

(SELECT UniqueID, [Name], BirthDate, Comment, ROW_NUMBER()
OVER(ORDER BY BirthDate) AS RowNum
FROM TestTable
) AS TestTableList
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex +
@maximumRows) - 1
and:

ALTER PROCEDURE dbo.usp_GetTest TableCount

AS

SELECT
COUNT(*)
FROM
TestTable


The "custom class" is defined as follows:

Imports Microsoft.Visua lBasic
Imports System.Collecti ons.Generic
Imports system.data
Imports System.Data.Sql
Imports system.Data.Sql Client

'
'
'
Public Class TestTableClass
'
'
Private m_UniqueID As String = ""
Private m_Name As String = ""
Private m_BirthDate As DateTime = Nothing
Private m_Comment As String = ""
'
'
Public Property UniqueID() As String
Get
Return m_UniqueID
End Get
Set(ByVal value As String)
m_UniqueID = value
End Set
End Property
'
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property
'
Public Property BirthDate() As DateTime
Get
Return m_BirthDate
End Get
Set(ByVal value As DateTime)
m_BirthDate = value
End Set
End Property
'
Public Property Comment() As String
Get
Return m_Comment
End Get
Set(ByVal value As String)
m_Comment = value
End Set
End Property
'
'
'
Public Function GetTestTableCou nt() As Integer
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(C onfigurationMan ager.Connection Strings("SiteDB ").ToString )
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connect ion = oSQLConn
oSQLCmd.Command Type = CommandType.Sto redProcedure
oSQLCmd.Command Text = "usp_GetTestTab leCount"
'
intResult = oSQLCmd.Execute Scalar
'
oSQLConn.Close( )
'
End Function
'
'
Public Function GetTestTable(By Val startRowIndex As Integer, ByVal
maximumRows As Integer) As List(Of TestTableClass)
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim oSQLParam As SqlParameter
Dim oDR As SqlDataReader
Dim mTTC As TestTableClass
Dim mColl As List(Of TestTableClass) = New List(Of
TestTableClass)
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(C onfigurationMan ager.Connection Strings("SiteDB ").ToString )
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connect ion = oSQLConn
oSQLCmd.Command Type = CommandType.Sto redProcedure
oSQLCmd.Command Text = "usp_GetTestTab le"
'
oSQLParam = New SqlParameter
oSQLParam.SqlDb Type = SqlDbType.Int
oSQLParam.Direc tion = ParameterDirect ion.Input
oSQLParam.Param eterName = "startRowIn dex"
oSQLParam.Value = startRowIndex
oSQLCmd.Paramet ers.Add(oSQLPar am)
'
oSQLParam = New SqlParameter
oSQLParam.SqlDb Type = SqlDbType.Int
oSQLParam.Direc tion = ParameterDirect ion.Input
oSQLParam.Param eterName = "maximumRow s"
oSQLParam.Value = maximumRows
oSQLCmd.Paramet ers.Add(oSQLPar am)
'
oDR = oSQLCmd.Execute Reader()
'
While oDR.Read
'
mTTC = New TestTableClass
mTTC.UniqueID = oDR.Item("Uniqu eID").ToString
mTTC.Name = oDR.Item("Name" ).ToString
mTTC.BirthDate = oDR.Item("Birth Date")
mTTC.Comment = oDR.Item("Comme nt").ToString
'
mColl.Add(mTTC)
'
End While
'
oSQLConn.Close( )
'
Return mColl
'
End Function
'
'
End Class

And the "Default.as px" page (which has nothing in it's code-behind) is
defined as follows:

<%@ Page Language="VB" AutoEventWireup ="false"
CodeFile="Defau lt.aspx.vb" Inherits="_Defa ult" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
TypeName="TestT ableClass" SelectCountMeth od="GetTestTabl eCount"
SelectMethod="G etTestTable" EnablePaging="T rue">
</asp:ObjectDataS ource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
AutoGenerateCol umns="False"
DataSourceID="O bjectDataSource 1">
<Columns>
<asp:BoundFie ld DataField="Uniq ueID"
HeaderText="Uni queID" SortExpression= "UniqueID" />
<asp:BoundFie ld DataField="Birt hDate"
HeaderText="Bir thDate" SortExpression= "BirthDate" />
<asp:BoundFie ld DataField="Name " HeaderText="Nam e"
SortExpression= "Name" />
<asp:BoundFie ld DataField="Comm ent"
HeaderText="Com ment" SortExpression= "Comment" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

Nov 30 '06 #2
Hi Kevin,

Thanks for replying.

I have tried your first suggestion regarding turning off paging, and I
now seem to be able to get the GridView to display the records.

I did this by turning off both the "Enable Paging" property on the
Gridview control, and also turning off the "Enable Paging" property on
the ObjectDataSourc e. I had created a "GetTestTab le" overload method
that took no parameters and just returned the complete table's worth
of data.

I was even able to turn the "Enable Paging" property of the
ObjectDataSourc e control back ON (which would then utilise the
GetTestTable method that takes the startRow and maximumRows
parameters) - I stepped through this function call and saw that
ASP.NET was passing in 0 (zero) for both the startRow and maximumRows
parameters (presumably because the "Enable Paging" property of the
Gridview control was still switched off). I was able to change these
values "in place" and watch the function run, and return the first 10
records from the table. These records would then be displayed within
the Gridview control (albeit without the "paging" options being
displayed).

So, it seems that the problem manifests itself when the "Enable
Paging" property of the GridView control is turned on, since the
paging that is happening within the ObjectDataSourc e seems to be
working correctly.

I have not tried your second suggestion (regarding returning a
DataTable rather then a generic list) since after trying the first
suggestion, the Gridview happily displayed my records.

Do you have any other suggestions as to what may cause the Gridview to
not display any records, even though the ObjectDatasourc e is correctly
returning records to be displayed ????

Thanks in advance.
Regards,
Greg.
On Thu, 30 Nov 2006 15:07:02 +1100, "Kevin Frey"
<ke**********@h otmail.comwrote :
>Why not try:

1. Turn off the paging.

2. Change the type of data structure being returned, instead of List< >.
Start with a simple DataTable being returned.

And see if these produce different outcomes.

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:md******* *************** **********@4ax. com...
>Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSour ce".
In turn, this ObjectDatasourc e gets it's data from a strongly-typed
business object within my code.
[Snip!]
Nov 30 '06 #3
Are you setting the PageSize in the GridView? This is the only simple thing
that comes to mind (and I don't have much experience with ObjectDataSourc e).

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:j0******** *************** *********@4ax.c om...
Hi Kevin,

Thanks for replying.

I have tried your first suggestion regarding turning off paging, and I
now seem to be able to get the GridView to display the records.

I did this by turning off both the "Enable Paging" property on the
Gridview control, and also turning off the "Enable Paging" property on
the ObjectDataSourc e. I had created a "GetTestTab le" overload method
that took no parameters and just returned the complete table's worth
of data.

I was even able to turn the "Enable Paging" property of the
ObjectDataSourc e control back ON (which would then utilise the
GetTestTable method that takes the startRow and maximumRows
parameters) - I stepped through this function call and saw that
ASP.NET was passing in 0 (zero) for both the startRow and maximumRows
parameters (presumably because the "Enable Paging" property of the
Gridview control was still switched off). I was able to change these
values "in place" and watch the function run, and return the first 10
records from the table. These records would then be displayed within
the Gridview control (albeit without the "paging" options being
displayed).

So, it seems that the problem manifests itself when the "Enable
Paging" property of the GridView control is turned on, since the
paging that is happening within the ObjectDataSourc e seems to be
working correctly.

I have not tried your second suggestion (regarding returning a
DataTable rather then a generic list) since after trying the first
suggestion, the Gridview happily displayed my records.

Do you have any other suggestions as to what may cause the Gridview to
not display any records, even though the ObjectDatasourc e is correctly
returning records to be displayed ????

Thanks in advance.
Regards,
Greg.
On Thu, 30 Nov 2006 15:07:02 +1100, "Kevin Frey"
<ke**********@h otmail.comwrote :
>>Why not try:

1. Turn off the paging.

2. Change the type of data structure being returned, instead of List< >.
Start with a simple DataTable being returned.

And see if these produce different outcomes.

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:md****** *************** ***********@4ax .com...
>>Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSour ce".
In turn, this ObjectDatasourc e gets it's data from a strongly-typed
business object within my code.
[Snip!]

Dec 1 '06 #4
One other comment - have you setup a SelectCountMeth od in the
ObjectDataSourc e and your data provider?

This may also have something to do with it - but admittedly this suggestion
is merely a guess.

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:j0******** *************** *********@4ax.c om...
Hi Kevin,

Thanks for replying.

I have tried your first suggestion regarding turning off paging, and I
now seem to be able to get the GridView to display the records.

I did this by turning off both the "Enable Paging" property on the
Gridview control, and also turning off the "Enable Paging" property on
the ObjectDataSourc e. I had created a "GetTestTab le" overload method
that took no parameters and just returned the complete table's worth
of data.

I was even able to turn the "Enable Paging" property of the
ObjectDataSourc e control back ON (which would then utilise the
GetTestTable method that takes the startRow and maximumRows
parameters) - I stepped through this function call and saw that
ASP.NET was passing in 0 (zero) for both the startRow and maximumRows
parameters (presumably because the "Enable Paging" property of the
Gridview control was still switched off). I was able to change these
values "in place" and watch the function run, and return the first 10
records from the table. These records would then be displayed within
the Gridview control (albeit without the "paging" options being
displayed).

So, it seems that the problem manifests itself when the "Enable
Paging" property of the GridView control is turned on, since the
paging that is happening within the ObjectDataSourc e seems to be
working correctly.

I have not tried your second suggestion (regarding returning a
DataTable rather then a generic list) since after trying the first
suggestion, the Gridview happily displayed my records.

Do you have any other suggestions as to what may cause the Gridview to
not display any records, even though the ObjectDatasourc e is correctly
returning records to be displayed ????

Thanks in advance.
Regards,
Greg.
On Thu, 30 Nov 2006 15:07:02 +1100, "Kevin Frey"
<ke**********@h otmail.comwrote :
>>Why not try:

1. Turn off the paging.

2. Change the type of data structure being returned, instead of List< >.
Start with a simple DataTable being returned.

And see if these produce different outcomes.

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:md****** *************** ***********@4ax .com...
>>Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSour ce".
In turn, this ObjectDatasourc e gets it's data from a strongly-typed
business object within my code.
[Snip!]

Dec 1 '06 #5
Hi Kevin,

I'm not explicitly setting the PageSize of the Gridview, just simply
using it's default value of 10. This is working correctly in that the
method call to the "SelectMeth od" correctly returns only the first 10
rows from my database table.

As for the "SelectCountMet hod", yes, I also have that defined within
the properties of the ObjectDatasourc e, and can step through my code
and verify that the runtime is indeed calling this method and getting
back the total count of records (13 in this case).

One thing I've noticed is that the "SelectCountMet hod" is fired AFTER
the "SelectMeth od".

Thanks for your time so far, Kevin, but I'm not really any further
forward with this. It's so frustrating since I thought this would be
a really simple thing to achieve, and I'm sure I'm just missing
something really simple, but don't know what that is.

Any other thoughts or suggestions on what's going wrong?
Anyone?
Regards,
Greg.

On Fri, 1 Dec 2006 12:13:21 +1100, "Kevin Frey"
<ke**********@h otmail.comwrote :
>Are you setting the PageSize in the GridView? This is the only simple thing
that comes to mind (and I don't have much experience with ObjectDataSourc e).
>One other comment - have you setup a SelectCountMeth od in the
ObjectDataSour ce and your data provider?

This may also have something to do with it - but admittedly this suggestion
is merely a guess.

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:j0******* *************** **********@4ax. com...
>Hi Kevin,

Thanks for replying.
[SNIP!]
Dec 1 '06 #6

After much head-bashing, I finally found the problem in the simple
test code that I posted, and the problem was all me.

Look at this function:
Public Function GetTestTableCou nt() As Integer
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(C onfigurationMan ager.Connection Strings("SiteDB ").ToString )
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connect ion = oSQLConn
oSQLCmd.Command Type = CommandType.Sto redProcedure
oSQLCmd.Command Text = "usp_GetTestTab leCount"
'
intResult = oSQLCmd.Execute Scalar
'
oSQLConn.Close( )
'
End Function
Notice how it's supposed to return an Integer value with the total
count of the records in the database?

Notice how I'm getting this value, storing it in a private variable
that's local to this procedure, and then NEVER ACTUALLY RETURNING A
VALUE FROM THE PROCEDURE!!!!

Doh! [/Slaps forehead]

So, it's my bad...Sorry..

HOWEVER, this was just in the sample code that I posted. In my real
application, I WAS correctly returning a value from the
"SelectCountMet hod", HOWEVER, I noticed that I'd declared the return
value to be of type Long rather than Integer. Integer is the correct
return type (as per the MSDN documentation - a small fact I'd
initially overlooked) - but no errors are thrown if you (incorrectly)
use a Long, even with "Option Strict" set to True. !!

Since the actual value being returned ARE within the range of an
Integer, I'd have thought that they would be implicitly cast from
Longs down to Integers, however, this appears not to be the case. At
least, the Gridview will refuse to display any data if the return
value from the "SelectCountMet hod" is a Long rather than an Integer
type.

So, it was THIS small bug/error that caused my Gridview to display no
data.

Just thought I'd share this with everyone in case someone else
stumbles onto the same problem I had.
-Greg.
On Fri, 01 Dec 2006 09:30:06 +0000, Greg Lyles
<gr*******@mail inator.comwrote :
>Hi Kevin,

I'm not explicitly setting the PageSize of the Gridview, just simply
using it's default value of 10. This is working correctly in that the
method call to the "SelectMeth od" correctly returns only the first 10
rows from my database table.

As for the "SelectCountMet hod", yes, I also have that defined within
the properties of the ObjectDatasourc e, and can step through my code
and verify that the runtime is indeed calling this method and getting
back the total count of records (13 in this case).

One thing I've noticed is that the "SelectCountMet hod" is fired AFTER
the "SelectMeth od".

Thanks for your time so far, Kevin, but I'm not really any further
forward with this. It's so frustrating since I thought this would be
a really simple thing to achieve, and I'm sure I'm just missing
something really simple, but don't know what that is.

Any other thoughts or suggestions on what's going wrong?
Anyone?
Regards,
Greg.

On Fri, 1 Dec 2006 12:13:21 +1100, "Kevin Frey"
<ke**********@ hotmail.comwrot e:
>>Are you setting the PageSize in the GridView? This is the only simple thing
that comes to mind (and I don't have much experience with ObjectDataSourc e).
>>One other comment - have you setup a SelectCountMeth od in the
ObjectDataSou rce and your data provider?

This may also have something to do with it - but admittedly this suggestion
is merely a guess.

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:j0****** *************** ***********@4ax .com...
>>Hi Kevin,

Thanks for replying.
[SNIP!]
Dec 2 '06 #7
Because the SelectCountMeth od is presumably being called via some kind of
Reflection mechanism, I'm presuming that the mismatch in return value
results in the outcome that you describe.

Sorry I couldn't get you to the finish line, but at least you got there by
yourself in the end ;-)

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:en******** *************** *********@4ax.c om...
>
After much head-bashing, I finally found the problem in the simple
test code that I posted, and the problem was all me.

Look at this function:
Public Function GetTestTableCou nt() As Integer
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(C onfigurationMan ager.Connection Strings("SiteDB ").ToString )
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connect ion = oSQLConn
oSQLCmd.Command Type = CommandType.Sto redProcedure
oSQLCmd.Command Text = "usp_GetTestTab leCount"
'
intResult = oSQLCmd.Execute Scalar
'
oSQLConn.Close( )
'
End Function
Notice how it's supposed to return an Integer value with the total
count of the records in the database?

Notice how I'm getting this value, storing it in a private variable
that's local to this procedure, and then NEVER ACTUALLY RETURNING A
VALUE FROM THE PROCEDURE!!!!

Doh! [/Slaps forehead]

So, it's my bad...Sorry..

HOWEVER, this was just in the sample code that I posted. In my real
application, I WAS correctly returning a value from the
"SelectCountMet hod", HOWEVER, I noticed that I'd declared the return
value to be of type Long rather than Integer. Integer is the correct
return type (as per the MSDN documentation - a small fact I'd
initially overlooked) - but no errors are thrown if you (incorrectly)
use a Long, even with "Option Strict" set to True. !!

Since the actual value being returned ARE within the range of an
Integer, I'd have thought that they would be implicitly cast from
Longs down to Integers, however, this appears not to be the case. At
least, the Gridview will refuse to display any data if the return
value from the "SelectCountMet hod" is a Long rather than an Integer
type.

So, it was THIS small bug/error that caused my Gridview to display no
data.

Just thought I'd share this with everyone in case someone else
stumbles onto the same problem I had.
-Greg.
On Fri, 01 Dec 2006 09:30:06 +0000, Greg Lyles
<gr*******@mail inator.comwrote :
>>Hi Kevin,

I'm not explicitly setting the PageSize of the Gridview, just simply
using it's default value of 10. This is working correctly in that the
method call to the "SelectMeth od" correctly returns only the first 10
rows from my database table.

As for the "SelectCountMet hod", yes, I also have that defined within
the properties of the ObjectDatasourc e, and can step through my code
and verify that the runtime is indeed calling this method and getting
back the total count of records (13 in this case).

One thing I've noticed is that the "SelectCountMet hod" is fired AFTER
the "SelectMeth od".

Thanks for your time so far, Kevin, but I'm not really any further
forward with this. It's so frustrating since I thought this would be
a really simple thing to achieve, and I'm sure I'm just missing
something really simple, but don't know what that is.

Any other thoughts or suggestions on what's going wrong?
Anyone?
Regards,
Greg.

On Fri, 1 Dec 2006 12:13:21 +1100, "Kevin Frey"
<ke********** @hotmail.comwro te:
>>>Are you setting the PageSize in the GridView? This is the only simple
thing
that comes to mind (and I don't have much experience with
ObjectDataSo urce).
>>>One other comment - have you setup a SelectCountMeth od in the
ObjectDataSo urce and your data provider?

This may also have something to do with it - but admittedly this
suggestion
is merely a guess.

"Greg Lyles" <gr*******@mail inator.comwrote in message
news:j0***** *************** ************@4a x.com...
Hi Kevin,

Thanks for replying.
[SNIP!]

Dec 3 '06 #8
On Mon, 4 Dec 2006 10:13:53 +1100, "Kevin Frey"
<ke**********@h otmail.comwrote :

Hi Kevin.
>Because the SelectCountMeth od is presumably being called via some kind of
Reflection mechanism, I'm presuming that the mismatch in return value
results in the outcome that you describe.
Yes. The "SelectCoun t" method is indeed called via the runtime's own
reflection, and it seems not to like Longs (for this method, at
least). The Gridview will simply display no data (or your "No data"
caption, if you've got one set).

What was most frustrating, of course, is that no error was thrown when
this occured. This made "step-thru" debugging exceptionally
difficult. I could see my function getting the value correctly, and
returning it correctly from the function. Of course, stepping into
the next line of code after this doesn't work, since the next thing to
execute is the runtime's own reflection mechanism to invoke the call
to the "SelectCoun t" method, something which cannot be "stepped-thru".

Had an error been thrown due to the incorrect return type from the
"SelectCoun t" method, I'd have nailed this problem in 10 seconds flat!
:)

It seems that the runtime was receiving a valid "value", but not
within the correct, explicitly expressed type, thus the reflection
mechanism was probably passing a "count" value of zero through to the
Gridview control, hence no data.
>
Sorry I couldn't get you to the finish line, but at least you got there by
yourself in the end ;-)
I'm still very grateful for your input, Kevin. You certainly pointed
me in the right direction (in removing the paging, thus being able to
isolate just *where* the problem was occuring), so thanks very much.

This seemed to be one of those little idiosyncracies of .NET (as any
development platform has) that can easily confuse and cause much
hair-pulling, since the problem a) doesn't throw an error and b) is
hidden deep within the bowels of the framework/runtime itself.

Just hoping that, if someone else has the same problem I did, they can
find this thread, since I know how frustrating this one was!
Thanks again.

Regards,
Greg.

>
"Greg Lyles" <gr*******@mail inator.comwrote in message
news:en******* *************** **********@4ax. com...
>>
After much head-bashing, I finally found the problem in the simple
test code that I posted, and the problem was all me.

[SNIP!]
Dec 4 '06 #9

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

Similar topics

3
4924
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls are Web Control & not HTML control. One of these buttons whose title is Delete is added on the aspx page in design view & also I double clicked on this button in design view to get the onclick code for this button in the code behind page. & for...
3
3278
by: mosscliffe | last post by:
I have a gridview and in the GridView1_SelectedIndexChanged routine I am attempting to get at the data in the row I have done it successfully with cells 'Access the contents of a field in a GRIDVIEW Dim joe As String = GridView1.SelectedRow.Cells(1).Text lbxDebug.Items.Insert(0, joe) but I thought I would try to access the data via the 'FieldName'
1
1680
by: slayerx | last post by:
Quote: Originally Posted by comteck As far as I know, a report is just that.. a means of displaying data. I don't believe it is possible to make a selection in a report. You can however, make a selection from a combo box on a form, and then have this selection displayed on the report. comteck could you tell me how to do that
0
1277
by: gr8beer | last post by:
The gridview rebinds data before the RowCommand or RowEditing events fire. So, if a new record is added to the underlying datasource that changes the index of the row you are trying to edit, you get the wrong row displayed for editing. I am guessing same is true when deleting which is even worse, especially if you are not confirming on delete. How do I either force the gridview not to rebind the data when edit is selected or force the...
1
2767
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint working as alternatively assigned reader obj. to datasource of GridView. Here is the code for the aspx.cs page: ( The reader surely cootains data as its HasRows property is true). Plz help. Never got stuck this bad with a problem. For more...
1
2474
by: seadog | last post by:
Hi, I am having a problem displaying data in a textbox array. What I am trying to do is have 5 number enter 5 textboxes, starting from the first and working there way to the bottom textbox. What is happening is that the displaying of the data is not happening until the process is complete, I have tryed a for next loop, for x = 1 to 5, text1(x).text = char(5,1), next x, I have even tryed just text(0).text = char(5,1), sleep 500, text(1).text =...
6
12969
by: jaredciagar | last post by:
Hi Guys Can you help me please in my project, I have tblItemList in my SQL DB. I want to display all the data in my tblItemList in GridView control.... How Can I Do That in VB Script using VB.Net... Thank you... Please Help Me... Regards, Jared
11
2424
by: dba | last post by:
Have been displaying data from database using html for some time but just recently trying to display data back to "form". Can't find answer. <form method="post" action="<?php echo $PHP_SELF;?>"> First Name:<input type="text" size="12" maxlength="12" name="Fname"><br > Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br /> Gender:<br /> Male:<input type="radio" value="Male" name="gender"><br /> Female:<input...
0
8821
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9196
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9103
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5967
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.